Commit 00cd00e2 authored by Eric Duminil's avatar Eric Duminil
Browse files

Soon

parent 31c74498
......@@ -48,16 +48,51 @@ namespace config {
// co2ampel-test/devices/esp3a7c94/up {"app_id":"co2ampel-test","dev_id":"esp3a7c94","hardware_serial":"00xxxxxxxx","port":1,"counter":5,"payload_raw":"TJd7","payload_fields":{"co2":760,"rh":61.5,"temp":20.2},"metadata":{"time":"2020-12-23T23:00:51.44020438Z","frequency":867.5,"modulation":"LORA","data_rate":"SF7BW125","airtime":51456000,"coding_rate":"4/5","gateways":[{"gtw_id":"eui-xxxxxxxxxxxxxxxxxx","timestamp":1765406908,"time":"2020-12-23T23:00:51.402519Z","channel":5,"rssi":-64,"snr":7.5,"rf_chain":0,"latitude":22.7,"longitude":114.24,"altitude":450}]}}
// More info : https://www.thethingsnetwork.org/docs/applications/mqtt/quick-start.html
uint8_t hexToByte(char c) {
int v = -1;
if ((c >= '0') && (c <= '9')) {
v = (c - '0');
} else if ((c >= 'A') && (c <= 'F')) {
v = (c - 'A' + 10);
} else if ((c >= 'a') && (c <= 'f')) {
v = (c - 'a' + 10);
}
return v;
}
void parseConfig(uint8_t *buf, const char *hex, uint max_n, int step) {
int n = util::min(strlen(hex) / 2, max_n);
Serial.println(hex);
Serial.print("Size : ");
Serial.println(n);
for (int i = 0; i < n; i++) {
uint8_t r = hexToByte(hex[i * 2]) * 16 + hexToByte(hex[i * 2 + 1]);
buf[i] = r;
}
for (int var = 0; var < max_n; ++var) {
Serial.print(buf[var], HEX);
Serial.print(" ");
}
Serial.println();
Serial.println("-----");
}
void os_getArtEui(u1_t *buf) {
memcpy_P(buf, config::APPEUI, 8);
parseConfig(buf, config::lorawan_app_eui, 8, -1);
// memcpy_P(buf, config::APPEUI, 8);
}
void os_getDevEui(u1_t *buf) {
memcpy_P(buf, config::DEVEUI, 8);
parseConfig(buf, config::lorawan_device_eui, 8, -1);
// memcpy_P(buf, config::DEVEUI, 8);
}
void os_getDevKey(u1_t *buf) {
memcpy_P(buf, config::APPKEY, 16);
parseConfig(buf, config::lorawan_app_key, 16, 1);
// memcpy_P(buf, config::APPKEY, 16);
}
namespace lorawan {
......@@ -65,43 +100,11 @@ namespace lorawan {
bool connected = false;
char last_transmission[23] = "";
uint8_t hexToByte(char c) {
int v = -1;
if ((c >= '0') && (c <= '9')) {
v = (c - '0');
} else if ((c >= 'A') && (c <= 'F')) {
v = (c - 'A' + 10);
} else if ((c >= 'a') && (c <= 'f')) {
v = (c - 'a' + 10);
}
return v;
}
void parseConfig(const char *hex) {
int n = strlen(hex);
Serial.println(hex);
Serial.print("Size : ");
Serial.println(n);
for (int i = 0; i < n; i = i + 2) {
uint8_t r = hexToByte(hex[i]) << 4 | hexToByte(hex[i + 1]);
Serial.print(r, HEX);
Serial.print(" ");
}
Serial.println();
Serial.println("-----");
}
void initialize() {
Serial.print(F("Starting LoRaWAN. Frequency plan : "));
Serial.print(config::lorawan_frequency_plan);
Serial.println(F(" MHz."));
parseConfig(config::lorawan_device_eui);
parseConfig(config::lorawan_app_eui);
parseConfig(config::lorawan_app_key);
// More info about pin mapping : https://github.com/mcci-catena/arduino-lmic#pin-mapping
// Has been tested successfully with ESP32 TTGO LoRa32 V1, and might work with other ESP32+LoRa boards.
const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment