From 9aebd1258e3e1016fd512f7e0c1975931173c80c Mon Sep 17 00:00:00 2001 From: platenspeler Date: Sun, 20 May 2018 13:23:50 +0200 Subject: [PATCH] Version 5.1.0; Better debug possibilities in WebGUI, storage of LOG files on ESP8266, and well-known list of devices (with name) in WebGui See read.me and ESP-gateway.h --- ESP-sc-gway/ESP-sc-gway.h | 39 ++- ESP-sc-gway/ESP-sc-gway.ino | 94 +++++--- ESP-sc-gway/_gatewayMgt.ino | 6 +- ESP-sc-gway/_loraFiles.ino | 102 +++++--- ESP-sc-gway/_loraModem.ino | 39 +-- ESP-sc-gway/_oLED.ino | 6 +- ESP-sc-gway/_otaServer.ino | 12 +- ESP-sc-gway/_repeater.ino | 6 +- ESP-sc-gway/_sensor.ino | 9 +- ESP-sc-gway/_stateMachine.ino | 438 ++++++++++++++++++++-------------- ESP-sc-gway/_txRx.ino | 13 +- ESP-sc-gway/_utils.ino | 45 ++-- ESP-sc-gway/_wwwServer.ino | 164 +++++++++++-- ESP-sc-gway/loraFiles.h | 23 +- ESP-sc-gway/loraModem.h | 14 +- ESP-sc-gway/oLED.h | 6 +- README.md | 16 +- 17 files changed, 679 insertions(+), 353 deletions(-) diff --git a/ESP-sc-gway/ESP-sc-gway.h b/ESP-sc-gway/ESP-sc-gway.h index 59cf27a..95edc12 100644 --- a/ESP-sc-gway/ESP-sc-gway.h +++ b/ESP-sc-gway/ESP-sc-gway.h @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 H -// Date: 2018-04-16 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 H +// Date: 2018-05-03 // // Based on work done by Thomas Telkamp for Raspberry PI 1ch gateway and many others. // Contibutions of Dorijan Morelj and Andreas Spies for OLED support. @@ -19,7 +19,7 @@ // // ---------------------------------------------------------------------------------------- -#define VERSION "V.5.0.9.H; 180416a" +#define VERSION "V.5.1.0.H; 180503a" // This value of DEBUG determines whether some parts of code get compiled. // Also this is the initial value of debug parameter. @@ -212,6 +212,37 @@ // Serial Port speed #define _BAUDRATE 115200 // Works for debug messages to serial momitor +// We can put the gateway in such a mode that it will (only) recognize +// nodes that are put in a list of trusted nodes +// Values: +// 0: Do not use names for trusted Nodes +// 1: Use the nodes as a translation tabel for hex codes to names (in TLN) +// 2: Same as 1, but is nodes NOT in the nodes list below they are NOT +// forwarded or counted! (not yet fully implemented) +#define TRUSTED_NODES 1 +#if TRUSTED_NODES >= 1 +struct nodex { + uint32_t id; + char nm[32]; +}; + +// Add all your named and trusted nodes to this list +nodex nodes[] = { + { 0x260116BD , "lora-34 PIR node" }, // F=0 + { 0x26011152 , "lora-35 temp+humi node" }, // F=0 + { 0x2601148C , "lora-36 test node" }, // F=0 + { 0x26011B90 , "lora-39 temp DS18B20" }, // F=1 + { 0x260119A6 , "lora-40 airquality" }, // F=0 + { 0x2601117D , "lora-41 temp+humi SR04T" }, + { 0x26011514 , "lora-43 ch1, no sensors" }, // F=1 + { 0x26011D77 , "lora-45 not sensor" }, + { 0x2601160F , "lora-46 HTU21 metal case" }, // F=0 + { 0x26011E52 , "lora-53 gas sensor" }, // F=ALL + { 0x02020441 , "lora-65 Waterproof temp humi" },// F=0 + { 0x26011999 , "lora-901 distance sensor" } // F=0 +}; +#endif + // Wifi definitions // WPA is an array with SSID and password records. Set WPA size to number of entries in array // When using the WiFiManager, we will overwrite the first entry with the diff --git a/ESP-sc-gway/ESP-sc-gway.ino b/ESP-sc-gway/ESP-sc-gway.ino index a9ada1b..842fd37 100644 --- a/ESP-sc-gway/ESP-sc-gway.ino +++ b/ESP-sc-gway/ESP-sc-gway.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // Author: Maarten Westenberg (mw12554@hotmail.com) // // based on work done by Thomas Telkamp for Raspberry PI 1-ch gateway @@ -90,9 +90,8 @@ extern "C" { #include "AES-128_V10.h" #endif - - -int debug=1; // Debug level! 0 is no msgs, 1 normal, 2 extensive +uint8_t debug=1; // Debug level! 0 is no msgs, 1 normal, 2 extensive +uint8_t pdebug=0xFF; // Allow all atterns (departments) // You can switch webserver off if not necessary but probably better to leave it in. #if A_SERVER==1 @@ -146,6 +145,7 @@ time_t startTime = 0; // The time in seconds since 1970 that the server st // be aware that UTP time has to succeed for meaningful values. // We use this variable since millis() is reset every 50 days... uint32_t eventTime = 0; // Timing of _event to change value (or not). +uint32_t doneTime = 0; // Time to expire when CDDONE takes too long uint32_t statTime = 0; // last time we sent a stat message to server uint32_t pulltime = 0; // last time we sent a pull_data request to server uint32_t lastTmst = 0; // Last activity Timer @@ -436,6 +436,7 @@ int WlanReadWpa() { if (gwayConfig.sf != (uint8_t) 0) sf = (sf_t) gwayConfig.sf; ifreq = gwayConfig.ch; debug = gwayConfig.debug; + pdebug = gwayConfig.pdebug; _cad = gwayConfig.cad; _hop = gwayConfig.hop; gwayConfig.boots++; // Every boot of the system we increase the reset @@ -472,12 +473,13 @@ int WlanReadWpa() { #if WIFIMANAGER==1 int WlanWriteWpa( char* ssid, char *pass) { +#if DUSB>=1 Serial.print(F("WlanWriteWpa:: ssid=")); Serial.print(ssid); Serial.print(F(", pass=")); Serial.print(pass); Serial.println(); - +#endif // Version 3.3 use of config file String s((char *) ssid); gwayConfig.ssid = s; @@ -542,7 +544,7 @@ int WlanConnect(int maxTry) { // Start with well-known access points in the list char *ssid = wpa[j].login; char *password = wpa[j].passw; - +#if DUSB>=1 Serial.print(i); Serial.print(':'); Serial.print(j); @@ -553,7 +555,7 @@ int WlanConnect(int maxTry) { Serial.print(password); } Serial.println(); - +#endif // Count the number of times we call WiFi.begin gwayConfig.wifis++; @@ -573,38 +575,55 @@ int WlanConnect(int maxTry) { while (((WiFi.status()) != WL_CONNECTED) && (agains < 10)) { agains++; delay(agains*500); +#if DUSB>=1 if (debug>=0) Serial.print("."); +#endif } // Check the connection status again switch (WiFi.status()) { case WL_CONNECTED: +#if DUSB>=1 if (debug>=0) Serial.println(F("WlanConnect:: CONNECTED")); // 3 +#endif return(1); break; case WL_IDLE_STATUS: +#if DUSB>=1 Serial.println(F("WlanConnect:: IDLE")); // 0 +#endif break; case WL_NO_SSID_AVAIL: +#if DUSB>=1 Serial.println(F("WlanConnect:: NO SSID")); // 1 +#endif break; case WL_CONNECT_FAILED: +#if DUSB>=1 Serial.println(F("WlanConnect:: FAILED")); // 4 +#endif break; case WL_DISCONNECTED: +#if DUSB>=1 Serial.println(F("WlanConnect:: DISCONNECTED")); // 6 - +#endif break; case WL_SCAN_COMPLETED: +#if DUSB>=1 Serial.println(F("WlanConnect:: SCAN COMPLETE")); // 2 +#endif break; case WL_CONNECTION_LOST: +#if DUSB>=1 Serial.println(F("WlanConnect:: LOST")); // 5 +#endif break; default: +#if DUSB>=1 Serial.print(F("WlanConnect:: code=")); Serial.println(WiFi.status()); +#endif break; } @@ -615,7 +634,7 @@ int WlanConnect(int maxTry) { // It should not be possible to be here while WL_CONNECTed if (WiFi.status() == WL_CONNECTED) { #if DUSB>=1 - if (debug>=3) { + if (( debug>=3 ) && ( pdebug & P_MAIN )) { Serial.print(F("WLAN connected")); Serial.println(); } @@ -625,11 +644,13 @@ int WlanConnect(int maxTry) { } else { #if WIFIMANAGER==1 +#if DUSB>=1 Serial.println(F("Starting Access Point Mode")); Serial.print(F("Connect Wifi to accesspoint: ")); Serial.print(AP_NAME); Serial.print(F(" and connect to IP: 192.168.4.1")); Serial.println(); +#endif wifiManager.autoConnect(AP_NAME, AP_PASSWD ); //wifiManager.startConfigPortal(AP_NAME, AP_PASSWD ); // At this point, there IS a Wifi Access Point found and connected @@ -1068,7 +1089,7 @@ void pullData() { Serial.print(pullIndex); Serial.print(F("> ")); for (i=0; i=1 Serial.flush(); + delay(500); if (SPIFFS.begin()) { @@ -1187,7 +1210,7 @@ void setup() { } else { } - +#endif #if SPIFF_FORMAT>=1 SPIFFS.format(); // Normally disabled. Enable only when SPIFFS corrupt #endif @@ -1319,7 +1342,10 @@ void setup() { //setTime((time_t)getNtpTime()); while (timeStatus() == timeNotSet) { - Serial.println(F("setupTime:: Time not set (yet)")); +#if DUSB>=1 + if (( debug>=0 ) && ( pdebug & P_MAIN )) + Serial.println(F("setupTime:: Time not set (yet)")); +#endif delay(500); time_t newTime; newTime = (time_t)getNtpTime(); @@ -1327,11 +1353,14 @@ void setup() { } // When we are here we succeeded in getting the time startTime = now(); // Time in seconds +#if DUSB>=1 Serial.print("Time: "); printTime(); Serial.println(); - +#endif writeGwayCfg(CONFIGFILE ); +#if DUSB>=1 Serial.println(F("Gateway configuration saved")); +#endif #endif //NTP_INTR #if A_SERVER==1 @@ -1347,6 +1376,7 @@ void setup() { if (_cad) { _state = S_SCAN; + sf = SF7; cadScanner(); // Always start at SF7 } else { @@ -1408,9 +1438,8 @@ void loop () // In this case we handle the interrupt ( e.g. message received) // in userspace in loop(). // - //while (_event != 0x00) { // - stateMachine(); // do the state machine - //} + stateMachine(); // do the state machine + // After a quiet period, make sure we reinit the modem and state machine. // The interval is in seconds (about 10 seconds) as this re-init @@ -1422,7 +1451,7 @@ void loop () (msgTime < statr[0].tmst) ) { #if DUSB>=1 - if (debug>=1) { + if (( debug>=1 ) && ( pdebug & P_MAIN )) { Serial.print("REINIT: "); Serial.print( _MSG_INTERVAL ); Serial.print(F(" ")); @@ -1432,6 +1461,7 @@ void loop () if ((_cad) || (_hop)) { _state = S_SCAN; + sf = SF7; cadScanner(); } else { @@ -1462,7 +1492,8 @@ void loop () // I event is set, we know that we have a (soft) interrupt. // After all necessary web/OTA services are scanned, we will - // reloop here for timing purposes. Do a less yield() as possible. + // reloop here for timing purposes. + // Do as less yield() as possible. // XXX 180326 if (_event == 1) return; else yield(); @@ -1471,10 +1502,11 @@ void loop () // We will not read Udp in this loop cycle then if (WlanConnect(1) < 0) { #if DUSB>=1 + if (( debug >= 0 ) && ( pdebug & P_MAIN )) Serial.println(F("loop: ERROR reconnect WLAN")); #endif - yield(); - return; // Exit loop if no WLAN connected + yield(); + return; // Exit loop if no WLAN connected } // So if we are connected @@ -1492,7 +1524,8 @@ void loop () // This command is found in byte 4 (buffer[3]) if (readUdp(packetSize) <= 0) { #if DUSB>=1 - if (debug>0) Serial.println(F("readUDP error")); + if (( debug>0 ) && ( pdebug & P_MAIN )) + Serial.println(F("readUDP error")); #endif break; } @@ -1510,14 +1543,14 @@ void loop () if ((nowSeconds - statTime) >= _STAT_INTERVAL) { // Wake up every xx seconds #if DUSB>=1 - if (debug>=2) { + if (( debug>=1 ) && ( pdebug & P_MAIN )) { Serial.print(F("STAT <")); Serial.flush(); } #endif sendstat(); // Show the status message and send to server #if DUSB>=1 - if (debug>=2) { + if (( debug>=2 ) && ( pdebug & P_MAIN )) { Serial.println(F(">")); if (debug>=2) Serial.flush(); } @@ -1537,7 +1570,9 @@ void loop () // could be battery but also other status info or sensor info if (sensorPacket() < 0) { +#if DUSB>=1 Serial.println(F("sensorPacket: Error")); +#endif } } #endif @@ -1552,20 +1587,21 @@ void loop () nowSeconds = now(); if ((nowSeconds - pulltime) >= _PULL_INTERVAL) { // Wake up every xx seconds #if DUSB>=1 - if (debug>=1) { + if (debug>=2) { Serial.print(F("PULL <")); - if (debug>=2) Serial.flush(); + if (debug>=1) Serial.flush(); } #endif pullData(); // Send PULL_DATA message to server initLoraModem(); // XXX 180326, after adapting this function if (_cad) { #if DUSB>=1 - if (debug>=1) { + if (( debug>=1 ) && ( pdebug & P_MAIN )) { Serial.print(F("PULL:: _state set to S_SCAN")); } #endif _state = S_SCAN; + sf = SF7; cadScanner(); } else { @@ -1575,7 +1611,7 @@ void loop () writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00); writeRegister(REG_IRQ_FLAGS, 0xFF); // Reset all interrupt flags #if DUSB>=1 - if (debug>=1) { + if (( debug>=1 ) && ( pdebug & P_MAIN )) { Serial.println(F(">")); if (debug>=2) Serial.flush(); } diff --git a/ESP-sc-gway/_gatewayMgt.ino b/ESP-sc-gway/_gatewayMgt.ino index 2523714..ef64360 100644 --- a/ESP-sc-gway/_gatewayMgt.ino +++ b/ESP-sc-gway/_gatewayMgt.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg +// Version 5.1.0 +// Date: 2018-04-17 // // Based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many others. diff --git a/ESP-sc-gway/_loraFiles.ino b/ESP-sc-gway/_loraFiles.ino index dca7988..182f1e0 100644 --- a/ESP-sc-gway/_loraFiles.ino +++ b/ESP-sc-gway/_loraFiles.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many others. @@ -21,6 +21,18 @@ // // The LoRa supporting functions are in the section below +// ---------------------------------------------------------------------------- +// Supporting function to readConfig +// ---------------------------------------------------------------------------- +void id_print (String id, String val) { +#if DUSB>=1 + if (( debug>=0 ) && ( pdebug & P_MAIN )) { + Serial.print(id); + Serial.print(F("=\t")); + Serial.println(val); + } +#endif +} // ---------------------------------------------------------------------------- @@ -29,12 +41,16 @@ int readConfig(const char *fn, struct espGwayConfig *c) { int tries = 0; +#if DUSB>=1 Serial.print(F("readConfig:: Starting ")); - +#endif if (!SPIFFS.exists(fn)) { +#if DUSB>=1 + if (( debug >= 0 ) && ( pdebug & P_MAIN )) Serial.print(F("ERROR:: readConfig, file=")); Serial.print(fn); Serial.print(F(" does not exist .. Formatting")); +#endif SPIFFS.format(); return(-1); } @@ -48,7 +64,7 @@ int readConfig(const char *fn, struct espGwayConfig *c) { while (f.available()) { #if DUSB>=1 - if (debug>=0) { + if (( debug>=0 ) && ( pdebug & P_MAIN )) { Serial.print('.'); } #endif @@ -57,7 +73,10 @@ int readConfig(const char *fn, struct espGwayConfig *c) { // if (tries >= 10) { f.close(); - Serial.println(F("Formatting")); +#if DUSB>=1 + if (( debug >= 0 ) && ( pdebug & P_MAIN )) + Serial.println(F("Formatting")); +#endif SPIFFS.format(); f = SPIFFS.open(fn, "r"); tries = 0; @@ -67,29 +86,33 @@ int readConfig(const char *fn, struct espGwayConfig *c) { String val=f.readStringUntil('\n'); if (id == "SSID") { // WiFi SSID - Serial.print(F("SSID=")); Serial.println(val); + id_print(id, val); (*c).ssid = val; // val contains ssid, we do NO check } //else if (id == "PASS") { // WiFi Password - // Serial.print(F("PASS=")); Serial.println(val); + // id_print(id, val); // (*c).pass = val; //} else if (id == "CH") { // Frequency Channel - Serial.print(F("CH=")); Serial.println(val); + id_print(id,val); (*c).ch = (uint32_t) val.toInt(); } else if (id == "SF") { // Spreading Factor - Serial.print(F("SF =")); Serial.println(val); + id_print(id, val); (*c).sf = (uint32_t) val.toInt(); } else if (id == "FCNT") { // Frame Counter - Serial.print(F("FCNT=")); Serial.println(val); + id_print(id, val); (*c).fcnt = (uint32_t) val.toInt(); } - else if (id == "DEBUG") { // Frame Counter - Serial.print(F("DEBUG=")); Serial.println(val); + else if (id == "DEBUG") { // Debug Level + id_print(id, val); (*c).debug = (uint8_t) val.toInt(); } + else if (id == "PDEBUG") { // pDebug Pattern + Serial.print(F("PDEBUG=")); Serial.println(val); + (*c).pdebug = (uint8_t) val.toInt(); + } else if (id == "CAD") { // CAD setting Serial.print(F("CAD=")); Serial.println(val); (*c).cad = (uint8_t) val.toInt(); @@ -99,55 +122,55 @@ int readConfig(const char *fn, struct espGwayConfig *c) { (*c).hop = (uint8_t) val.toInt(); } else if (id == "BOOTS") { // BOOTS setting - Serial.print(F("BOOTS=")); Serial.println(val); + id_print(id, val); (*c).boots = (uint8_t) val.toInt(); } else if (id == "RESETS") { // RESET setting - Serial.print(F("RESETS=")); Serial.println(val); + id_print(id, val); (*c).resets = (uint8_t) val.toInt(); } else if (id == "WIFIS") { // WIFIS setting - Serial.print(F("WIFIS=")); Serial.println(val); + id_print(id, val); (*c).wifis = (uint8_t) val.toInt(); } else if (id == "VIEWS") { // VIEWS setting - Serial.print(F("VIEWS=")); Serial.println(val); + id_print(id, val); (*c).views = (uint8_t) val.toInt(); } else if (id == "NODE") { // NODE setting - Serial.print(F("NODE=")); Serial.println(val); + id_print(id, val); (*c).isNode = (uint8_t) val.toInt(); } else if (id == "REFR") { // REFR setting - Serial.print(F("REFR=")); Serial.println(val); + id_print(id, val); (*c).refresh = (uint8_t) val.toInt(); } else if (id == "REENTS") { // REENTS setting - Serial.print(F("REENTS=")); Serial.println(val); + id_print(id, val); (*c).reents = (uint8_t) val.toInt(); } else if (id == "NTPERR") { // NTPERR setting - Serial.print(F("NTPERR=")); Serial.println(val); + id_print(id, val); (*c).ntpErr = (uint8_t) val.toInt(); } else if (id == "NTPETIM") { // NTPERR setting - Serial.print(F("NTPETIM=")); Serial.println(val); + id_print(id, val); (*c).ntpErrTime = (uint32_t) val.toInt(); } else if (id == "NTPS") { // NTPS setting - Serial.print(F("NTPS=")); Serial.println(val); + id_print(id, val); (*c).ntps = (uint8_t) val.toInt(); } else if (id == "FILENO") { // log FILENO setting - Serial.print(F("FILENO=")); Serial.println(val); + id_print(id, val); (*c).logFileNo = (uint8_t) val.toInt(); } else if (id == "FILEREC") { // FILEREC setting - Serial.print(F("FILEREC=")); Serial.println(val); + id_print(id, val); (*c).logFileRec = (uint8_t) val.toInt(); } else if (id == "FILENUM") { // FILEREC setting - Serial.print(F("FILENUM=")); Serial.println(val); + id_print(id, val); (*c).logFileNum = (uint8_t) val.toInt(); } else { @@ -171,17 +194,17 @@ int readConfig(const char *fn, struct espGwayConfig *c) { // ---------------------------------------------------------------------------- int writeGwayCfg(const char *fn) { - gwayConfig.sf = (uint8_t) sf; gwayConfig.ssid = WiFi.SSID(); //gwayConfig.pass = WiFi.PASS(); // XXX We should find a way to store the password too - gwayConfig.ch = ifreq; + gwayConfig.ch = ifreq; // Frequency Index + gwayConfig.sf = (uint8_t) sf; // Spreading Factor gwayConfig.debug = debug; + gwayConfig.pdebug = pdebug; gwayConfig.cad = _cad; gwayConfig.hop = _hop; #if GATEWAYNODE==1 gwayConfig.fcnt = frameCount; #endif - return(writeConfig(fn, &gwayConfig)); } @@ -211,6 +234,7 @@ int writeConfig(const char *fn, struct espGwayConfig *c) { f.print("SF"); f.print('='); f.print((*c).sf); f.print('\n'); f.print("FCNT"); f.print('='); f.print((*c).fcnt); f.print('\n'); f.print("DEBUG"); f.print('='); f.print((*c).debug); f.print('\n'); + f.print("PDEBUG"); f.print('='); f.print((*c).pdebug); f.print('\n'); f.print("CAD"); f.print('='); f.print((*c).cad); f.print('\n'); f.print("HOP"); f.print('='); f.print((*c).hop); f.print('\n'); f.print("NODE"); f.print('='); f.print((*c).isNode); f.print('\n'); @@ -270,24 +294,28 @@ void addLog(const unsigned char * line, int cnt) // Make sure to write the config record also if (!SPIFFS.exists(fn)) { #if DUSB>=1 - Serial.print(F("ERROR:: addLog:: file=")); - Serial.print(fn); - Serial.print(F(" does not exist .. rec=")); - Serial.print(gwayConfig.logFileRec); - Serial.println(); + if (( debug >= 1 ) && ( pdebug & P_GUI )) { + Serial.print(F("ERROR:: addLog:: file=")); + Serial.print(fn); + Serial.print(F(" does not exist .. rec=")); + Serial.print(gwayConfig.logFileRec); + Serial.println(); + } #endif } File f = SPIFFS.open(fn, "a"); if (!f) { #if DUSB>=1 - Serial.println("file open failed="); - Serial.println(fn); + if (debug>=1) { + Serial.println("file open failed="); + Serial.println(fn); + } #endif } #if DUSB>=1 - if (debug>=1) { + if (( debug>=1 ) && ( pdebug & P_RX )) { Serial.print(F("addLog:: fileno=")); Serial.print(gwayConfig.logFileNo); Serial.print(F(", rec=")); diff --git a/ESP-sc-gway/_loraModem.ino b/ESP-sc-gway/_loraModem.ino index d3cc1e3..a936999 100644 --- a/ESP-sc-gway/_loraModem.ino +++ b/ESP-sc-gway/_loraModem.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many others. @@ -90,7 +90,7 @@ // The variable is for obvious reasons valid for read and write traffic at the // same time. Since both read and write mean that we write to the SPI interface. // Parameters: -// Address: SPI address to read from. Type unint8_t +// Address: SPI address to read from. Type uint8_t // Return: // Value read from address // ---------------------------------------------------------------------------- @@ -307,6 +307,7 @@ void opmode(uint8_t mode) void hop() { ifreq = (ifreq + 1) % NUM_HOPS ; // Increment the freq round robin + freq = freqs[ifreq]; setFreq(freqs[ifreq]); sf = SF7; // Set the sf to SF7 @@ -357,15 +358,14 @@ uint8_t receivePkt(uint8_t *payload) if (irqflags & IRQ_LORA_CRCERR_MASK) { #if DUSB>=1 - if (debug>=0) { - Serial.print(F("Err RxPkg:: CRC, =")); + if (( debug>=0) && ( pdebug & P_RADIO )) { + Serial.print(F("Err RxPkt:: CRC, =")); SerialTime(); Serial.println(); } #endif // Reset CRC flag 0x20 //writeRegister(REG_IRQ_FLAGS, (uint8_t)(IRQ_LORA_CRCERR_MASK | IRQ_LORA_RXDONE_MASK)); // 0x12; clear CRC (== 0x20) flag - //_event=0; //writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00); //writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); // XXX 180324 done in state machine return 0; @@ -377,8 +377,8 @@ uint8_t receivePkt(uint8_t *payload) else if ((irqflags & IRQ_LORA_HEADER_MASK) == false) { #if DUSB>=1 - if (debug>=0) { - Serial.println(F("Err RxPkg:: HEADER")); + if (( debug>=0) && ( pdebug & P_RADIO )) { + Serial.println(F("Err RxPkt:: HEADER")); } #endif // Reset VALID-HEADER flag 0x10 @@ -415,7 +415,7 @@ uint8_t receivePkt(uint8_t *payload) if (receivedCount > PAYLOAD_LENGTH) { #if DUSB>=1 - if (debug>=0) { + if (( debug>=0 ) & ( pdebug & P_RADIO )) { Serial.print(F("rxPkt:: receivedCount=")); Serial.println(receivedCount); } @@ -430,7 +430,7 @@ uint8_t receivePkt(uint8_t *payload) writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); // Reset ALL interrupts #if DUSB>=1 - if (debug>=0) { + if (( debug>=0 ) && ( pdebug & P_RADIO )){ Serial.print(F("rxPkt:: t=")); SerialTime(); @@ -675,11 +675,15 @@ void txLoraModem(uint8_t *payLoad, uint8_t payLength, uint32_t tmst, uint8_t sfT void rxLoraModem() { // 1. Put system in LoRa mode - //opmode(OPMODE_LORA); + //opmode(OPMODE_LORA); // Is already so // 2. Put the radio in sleep mode - opmode(OPMODE_STANDBY); - //opmode(OPMODE_SLEEP); // set 0x01 to 0x00 + //if (_hop) { + // opmode(OPMODE_SLEEP); // power save, and enable switch FSK/OOK ro LORA + //} + //else { + opmode(OPMODE_STANDBY); // CAD set 0x01 to 0x00 + //} // 3. Set frequency based on value in freq setFreq(freqs[ifreq]); // set to 868.1MHz @@ -765,14 +769,11 @@ void cadScanner() // 2. Put the radio in sleep mode opmode(OPMODE_STANDBY); // Was old value - // As we can come back from S_TX with other frequencies and SF - // reset both to good values for cadScanner - // 3. Set frequency based on value in ifreq // XXX New, might be needed when receiving down setFreq(freqs[ifreq]); - // For every time we stat the scanner, we set the SF to the begin value - sf = SF7; // we make SF the lower, this is faster! + // For every time we start the scanner, we set the SF to the begin value + //sf = SF7; // XXX 180501 Not by default // 4. Set spreading Factor and CRC setRate(sf, 0x04); diff --git a/ESP-sc-gway/_oLED.ino b/ESP-sc-gway/_oLED.ino index 93a09ae..c56eee0 100644 --- a/ESP-sc-gway/_oLED.ino +++ b/ESP-sc-gway/_oLED.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many others. diff --git a/ESP-sc-gway/_otaServer.ino b/ESP-sc-gway/_otaServer.ino index ba4b669..acb9238 100644 --- a/ESP-sc-gway/_otaServer.ino +++ b/ESP-sc-gway/_otaServer.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // // All rights reserved. This program and the accompanying materials @@ -30,8 +30,9 @@ void setupOta(char *hostname) { ArduinoOTA.begin(); +#if DUSB>=1 Serial.println(F("setupOta:: Started")); - +#endif // Hostname defaults to esp8266-[ChipID] ArduinoOTA.setHostname(hostname); @@ -65,10 +66,11 @@ void setupOta(char *hostname) { else if (error == OTA_END_ERROR) Serial.println("End Failed"); }); - +#if DUSB>=1 Serial.println("Ready"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); +#endif // Only if the Webserver is active also #if A_SERVER==2 // Displaed for the moment diff --git a/ESP-sc-gway/_repeater.ino b/ESP-sc-gway/_repeater.ino index b324b2e..d0c981d 100644 --- a/ESP-sc-gway/_repeater.ino +++ b/ESP-sc-gway/_repeater.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg -// Verison 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg +// Verison 5.1.0 +// Date: 2018-04-17 // // All rights reserved. This program and the accompanying materials // are made available under the terms of the MIT License diff --git a/ESP-sc-gway/_sensor.ino b/ESP-sc-gway/_sensor.ino index 475f1bb..e40dc05 100644 --- a/ESP-sc-gway/_sensor.ino +++ b/ESP-sc-gway/_sensor.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg -// Verison 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg +// Verison 5.1.0 +// Date: 2018-04-17 // // All rights reserved. This program and the accompanying materials // are made available under the terms of the MIT License @@ -486,8 +486,9 @@ int sensorPacket() { #endif if (_cad) { - // Set the state to CAD scanning after receiving + // Set the state to CAD scanning after sending a packet _state = S_SCAN; // Inititialise scanner + sf = SF7; cadScanner(); } else { diff --git a/ESP-sc-gway/_stateMachine.ino b/ESP-sc-gway/_stateMachine.ino index 6cf4168..c6512bb 100644 --- a/ESP-sc-gway/_stateMachine.ino +++ b/ESP-sc-gway/_stateMachine.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-25 // // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many others. @@ -75,80 +75,144 @@ void stateMachine() uint8_t flags = readRegister(REG_IRQ_FLAGS); uint8_t mask = readRegister(REG_IRQ_FLAGS_MASK); uint8_t intr = flags & ( ~ mask ); // Only react on non masked interrupts - uint8_t rssi; - - // If there is NO event interrupt detected but the state machine is called anyway - // then we know its a soft interrupt and we wait the frequency _hop out. - // - if ((intr == 0x00) && (_hop)) - { - // If we hop and we are scanning we have to make sure that we allow enought time to detect - // CDDONE or CDECT. But if we do not receive interrupts, we have to schedule - // another hop after EVENT_WAIT microseconds. - // The process is such that we scan on SF7 (the shortest) preamble and if - // nothing detected within a scan, we switch to another frequency. - // - if ((_state == S_SCAN) || (_state == S_CAD)) { - - // If there is no interrupt, _event has been set by software and not in - // an interrupt handler. - _event=0; - - // As long as there is no interrupt event, stay in this loop. - // A real interrupt on one of the dio pins will be read by the - // system and the register REG_IRQ_FLAGS will reflect this. - // For SF7, one token takes XXX uSecs - // - eventTime = micros(); - while ( (_event == 0) && - (((micros() - eventTime + 0xFFFFFFFF) % 0xFFFFFFFF) < EVENT_WAIT) && - ((_state == S_SCAN) || (_state == S_CAD)) ) - { - // If an event arises during this wait, we break the while - delayMicroseconds(10); // XXX 180103 - } - - yield(); - - // If we received a real interrupt, take the action - // by the stateMachine and read interrupt. - // - if (_event != 0) { - _event=0; - flags = readRegister(REG_IRQ_FLAGS); - mask = readRegister(REG_IRQ_FLAGS_MASK); - //intr = intr | (flags & ( ~ mask )); - intr = (flags & ( ~ mask )); #if DUSB>=1 - if (debug >=1 ) SerialStat(intr); -#endif - } - // If no interrupt received, switch both channel/frequency - // and switch Spreading Factor (SF) - // - else { - hop(); // increment ifreq = (ifreq + 1) % NUM_HOPS ; - cadScanner(); // Reset to initial SF, leave frequency "freqs[ifreq]" - _state = S_SCAN; -#if DUSB>=1 - if (debug >= 1) SerialStat(intr); + if (intr != flags) { + Serial.print(F("FLAG ::")); + SerialStat(intr); + } #endif - _event=1; //XXX 06/03, start State Machine again - return; - } - }// SCAN or CAD - - // If not in SCAN or CAD state - // we only act on interrupts in this mode ((_event!=0) && (intr!=0)) - // - else { - + uint8_t rssi; + _event=0; // Reset the interrupt detector + + // If Hopping is selected AND if there is NO event interrupt detected + // and the state machine is called anyway + // then we know its a soft interrupt and we do nothing and return to main loop. + // + if ((_hop) && (intr == 0x00) ) + { + // If we are not in scanning state, and there will be an interrupt coming, + // In state S_RX it could be RXDONE in which case allow kernel time + // + if ((_state == S_SCAN) || (_state == S_CAD)) { + _event=0; + + uint32_t eventWait = EVENT_WAIT; + switch (_state) { + case S_INIT: eventWait = 0; break; + case S_SCAN: eventWait = EVENT_WAIT * 1; break; + case S_CAD: eventWait = EVENT_WAIT * 1; break; + case S_RX: eventWait = EVENT_WAIT * 8; break; + case S_TX: eventWait = EVENT_WAIT * 1; break; + case S_TXDONE: eventWait = EVENT_WAIT * 4; break; + default: + eventWait=0; +#if DUSB>=1 + Serial.print(F("DEF :: ")); + SerialStat(intr); +#endif + } + // + // So we init the wait time for RXDONE based on the current SF. + // As for highter CF it takes longer to receive symbols + // + uint32_t doneWait = DONE_WAIT; // Initial value + switch (sf) { + case SF7: + break; + case SF8: + doneWait *= 2; // Assume symbols in SF8 take twice the time of SF7 + break; + case SF9: + doneWait *= 4; + break; + case SF10: + doneWait *= 8; + break; + case SF11: + doneWait *= 16; + break; + case SF12: + doneWait *= 32; + break; + default: +#if DUSB>=1 + Serial.print(F("PRE:: DEF set")); + Serial.println(); +#endif + } + + // If micros is starting over again after 51 minutes + // it's value is smaller than an earlier value of eventTime/doneTime + // + if (eventTime > micros()) eventTime=micros(); + if (doneTime > micros()) doneTime=micros(); + + if ((micros() - doneTime) > doneWait ) + { + _state = S_SCAN; + hop(); // increment ifreq = (ifreq + 1) % NUM_HOPS ; + cadScanner(); // Reset to initial SF, leave frequency "freqs[ifreq]" + rxLoraModem(); +#if DUSB>=1 + if (( debug >= 1 ) && ( pdebug & P_PRE )) { + Serial.print(F("DONE:: ")); + SerialStat(intr); + } +#endif + eventTime=micros(); // reset the timer on timeout + doneTime=micros(); // reset the timer on timeout + return; + } + // If timeout occurs and still no _event, then increase SF + // and when reaching SF12 hop and return + // Start scanning again + // + if ((micros() - eventTime) > eventWait ) + { + _state = S_SCAN; + hop(); // increment ifreq = (ifreq + 1) % NUM_HOPS ; + cadScanner(); // Reset to initial SF, leave frequency "freqs[ifreq]" +#if DUSB>=1 + if (( debug >= 2 ) && ( pdebug & P_PRE )) { + Serial.print(F("HOP :: ")); + SerialStat(intr); + } +#endif + eventTime=micros(); // reset the timer on timeout + doneTime=micros(); // reset the timer on timeout + return; + } - } + + // If we are here, NO timeout has occurred + // So we need to return to the main State Machine + // as there was NO interrupt + +#if DUSB>=1 + if (( debug>=3 ) && ( pdebug & P_PRE )) { + Serial.print(F("PRE:: eventTime=")); + Serial.print(eventTime); + Serial.print(F(", micros=")); + Serial.print(micros()); + Serial.print(F(": ")); + SerialStat(intr); + } +#endif + + } // if SCAN or CAD + + // else, S_RX of S_TX for example + else { + yield(); + } // else S_RX or S_TX, TXDONE + }// intr==0 && _hop - - + + + doneTime = micros(); // We need CDDONE or other intr to reset timeout + + // This is the actual state machine of the gateway // and its next actions are depending on the state we are in. // For hop situations we do not get interrupts, so we have to @@ -161,13 +225,14 @@ void stateMachine() // The initLoraModem() function is already called in setup(); // case S_INIT: -#if DUSB>=2 - if (debug >= 1) { +#if DUSB>=1 + if (( debug>=1 ) && ( pdebug & P_PRE )) { Serial.println(F("S_INIT")); } #endif // new state, needed to startup the radio (to S_SCAN) - writeRegister(REG_IRQ_FLAGS, 0xFF ); // Clear ALL interrupts + writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF ); // Clear ALL interrupts + writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00 ); // Clear ALL interrupts _event=0; break; @@ -192,35 +257,37 @@ void stateMachine() writeRegister(REG_DIO_MAPPING_1, ( MAP_DIO0_LORA_RXDONE | MAP_DIO1_LORA_RXTOUT | - MAP_DIO2_LORA_NOP | + MAP_DIO2_LORA_NOP | MAP_DIO3_LORA_CRC)); - // Since new state is S_RX, accept no interrupts except RXDONE or RXTOUT + // Since new state is S_RX, accept no interrupts except RXDONE or RXTOUT + // HEADER and CRCERR writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) ~( IRQ_LORA_RXDONE_MASK | IRQ_LORA_RXTOUT_MASK | IRQ_LORA_HEADER_MASK | IRQ_LORA_CRCERR_MASK)); - - delayMicroseconds( RSSI_WAIT ); // Wait some microseconds less + + writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF ); // reset all interrupt flags // Starting with version 5.0.1 the waittime is dependent on the SF // So for SF12 we wait longer (2^7 == 128 uSec) and for SF7 4 uSec. //delayMicroseconds( (0x01 << ((uint8_t)sf - 5 )) ); + delayMicroseconds( RSSI_WAIT ); // Wait some microseconds less rssi = readRegister(REG_RSSI); // Read the RSSI _rssi = rssi; // Read the RSSI in the state variable - _event = 0; // Make 0, as soon aswe have an interrupt - writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF ); // reset all interrupt flags - + _event = 0; // Make 0, as soon as we have an interrupt +// XXX IRQ writeregister was here May 11 + detTime = micros(); + #if DUSB>=1 - if (debug>=1) { - Serial.print(F("SCAN:: CDDETD, f=")); - Serial.println(ifreq); + if (( debug>=1 ) && ( pdebug & P_SCAN )) { + Serial.print(F("SCAN:: ")); + SerialStat(intr); } #endif - detTime = micros(); }//if // CDDONE @@ -233,39 +300,48 @@ void stateMachine() opmode(OPMODE_CAD); rssi = readRegister(REG_RSSI); // Read the RSSI +#if DUSB>=1 + if (( debug>=2 ) && ( pdebug & P_SCAN )) { + Serial.print(F("SCAN:: f=")); + Serial.print(ifreq); + Serial.print(F(", sf=")); + Serial.print(sf); + Serial.print(F("CDDONE: ")); + SerialStat(intr); + } +#endif // We choose the generic RSSI as a sorting mechanism for packages/messages // The pRSSI (package RSSI) is calculated upon successful reception of message // So we expect that this value makes little sense for the moment with CDDONE. // Set the rssi as low as the noise floor. Lower values are not recognized then. // Every cycle starts with ifreq==0 and sf=SF7 (or the set init SF) // - if ( rssi > RSSI_LIMIT ) // Is set to 35 + //if ( rssi > RSSI_LIMIT ) // Is set to 35 + if ( rssi > (RSSI_LIMIT - (_hop * 7))) // Is set to 35, or 29 for HOP { #if DUSB>=1 - if (debug>=2) { - Serial.println(F("S_SCAN:: -> CAD")); + if (( debug>=2 ) && ( pdebug & P_SCAN )) { + Serial.println(F("SCAN:: -> CAD: ")); + SerialStat(intr); } #endif - _state = S_CAD; // promote next level - if (_hop) { - _event=1; // if SCAN, goto CAD asap and next SF - } - else { - _event=0; // next CDDONE by interrupt XXXXX - } + _state = S_CAD; // promote to next level + _event=0; } // If the RSSI is not big enough we skip the CDDONE // and go back to scanning else { #if DUSB>=1 - if (debug>=3) { - Serial.print("S_SCAN:: rssi="); - Serial.println(rssi); + if (( debug>=2 ) && ( pdebug & P_SCAN )) { + Serial.print("SCAN:: rssi="); + Serial.print(rssi); + Serial.print(F(": ")); + SerialStat(intr); } #endif _state = S_SCAN; - _event=1; // loop() scan until CDDONE + //_event=1; // loop() scan until CDDONE } // Clear the CADDONE flag @@ -291,19 +367,20 @@ void stateMachine() // else if (intr == 0x00) { - //_state = S_SCAN; // Do this state again but now for other freq. - if (! _hop) _event = 0; // XXX 26/12/2017 !!! NEED + _event=0; // XXX 26/12/2017 !!! NEED } // Unkown Interrupt, so we have an error // else { #if DUSB>=1 - Serial.print(F("SCAN unknown:: ")); - SerialStat(intr); + if (( debug>=0 ) && ( pdebug & P_SCAN )) { + Serial.print(F("SCAN unknown:: ")); + SerialStat(intr); + } #endif _state=S_SCAN; - _event=1; // XXX 06/03 loop until interrupt + //_event=1; // XXX 06/03 loop until interrupt writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00); writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); } @@ -347,7 +424,7 @@ void stateMachine() // Reset all interrupts as soon as possible // But listen ONLY to RXDONE and RXTOUT interrupts writeRegister(REG_IRQ_FLAGS, IRQ_LORA_CDDETD_MASK | IRQ_LORA_RXDONE_MASK); - //writeRegister(REG_IRQ_FLAGS, 0xFF ); // XXX 180326, reset all CAD Detect interrupt flags + //writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF ); // XXX 180326, reset all CAD Detect interrupt flags _state = S_RX; // Set state to start receiving opmode(OPMODE_RX_SINGLE); // set reg 0x01 to 0x06, initiate READ @@ -357,25 +434,15 @@ void stateMachine() rssi = readRegister(REG_RSSI); // Read the RSSI _rssi = rssi; // Read the RSSI in the state variable - if (_hop) { - //_event=1; + detTime = micros(); #if DUSB>=1 - // XXX We see message under often in hop, but no RXDONE or RXTOUT - // and that should not be possible - if (debug>=1) { - Serial.print(F("S_CAD:: hop CDDET fr=")); - Serial.print(ifreq); - Serial.print(F(", sf=")); - Serial.println(sf); - } + if (( debug>=1 ) && ( pdebug & P_CAD )) { + Serial.print(F("CAD:: ")); + SerialStat(intr); + } #endif - } - // If not hop, we return to the state Machine immediately - else{ - //_event=1; // XXX 180324, was 1; - } - detTime=micros(); + }// CDDETD // Intr == CADDONE @@ -394,7 +461,7 @@ void stateMachine() _event=0; // XXX 180324, when increasing SF loop, ws 0x00 writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00); // Reset the interrupt mask //writeRegister(REG_IRQ_FLAGS, IRQ_LORA_CDDONE_MASK | IRQ_LORA_CDDETD_MASK); - writeRegister(REG_IRQ_FLAGS, 0xFF ); // This will prevent the CDDETD from being read + writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF ); // This will prevent the CDDETD from being read opmode(OPMODE_CAD); // Scanning mode @@ -402,7 +469,7 @@ void stateMachine() rssi = readRegister(REG_RSSI); // Read the RSSI #if DUSB>=1 - if (debug>=2) { + if (( debug>=2 ) && ( pdebug & P_CAD )) { Serial.print(F("S_CAD:: CDONE, SF=")); Serial.println(sf); } @@ -416,21 +483,16 @@ void stateMachine() // Reset Interrupts _event=1; // reset soft intr, to state machine again writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00); // Reset the interrupt mask - writeRegister(REG_IRQ_FLAGS, 0xFF ); // or IRQ_LORA_CDDONE_MASK + writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF ); // or IRQ_LORA_CDDONE_MASK _state = S_SCAN; // As soon as we reach SF12 do something - if (_hop) { - hop(); // but Change channels - } + sf = SF7; cadScanner(); // Which will reset SF to SF7 #if DUSB>=1 - if (debug>=2) { - Serial.print(F("CAD->SCAN:0x")); - Serial.print(ifreq); - Serial.print(F(":SF")); - Serial.print(sf); - Serial.println(); + if (( debug>=2 ) && ( pdebug & P_CAD )) { + Serial.print(F("CAD->SCAN:: ")); + SerialStat(intr); } #endif } @@ -444,7 +506,7 @@ void stateMachine() // else if (intr == 0x00) { #if DUSB>=0 - if (debug>=3) { + if (( debug>=3 ) && ( pdebug & P_CAD )) { Serial.println("Err CAD:: intr is 0x00"); } #endif @@ -456,12 +518,13 @@ void stateMachine() // else { #if DUSB>=1 - if (debug>=0) { + if (( debug>=0) && ( pdebug & P_CAD )) { Serial.print(F("Err CAD: Unknown::")); SerialStat(intr); } #endif _state = S_SCAN; + sf = SF7; cadScanner(); // Scan and set SF7 // Reset Interrupts @@ -471,7 +534,6 @@ void stateMachine() } break; //S_CAD - // -------------------------------------------------------------- // If we receive an RXDONE interrupt on dio0 with state==S_RX @@ -482,7 +544,7 @@ void stateMachine() // Go back to SCAN // case S_RX: - + if (intr & IRQ_LORA_RXDONE_MASK) { #if CRCCHECK==1 @@ -493,12 +555,13 @@ void stateMachine() // if (intr & IRQ_LORA_CRCERR_MASK) { #if DUSB>=1 - if ((debug>=0)&& - (intr & IRQ_LORA_CRCERR_MASK)) { - Serial.println(F("Rx CRC err")); + if (( debug>=0 ) && ( pdebug & P_RX )) { + Serial.print(F("Rx CRC err: ")); + SerialStat(intr); } #endif if (_cad) { + sf = SF7; _state = S_SCAN; cadScanner(); } @@ -535,7 +598,7 @@ void stateMachine() // - break if((LoraUp.payLength = receivePkt(LoraUp.payLoad)) <= 0) { #if DUSB>=1 - if (debug>=1) { + if (( debug>=1 ) && ( pdebug & P_RX )) { Serial.println(F("sMachine:: Error S-RX")); } #endif @@ -546,14 +609,17 @@ void stateMachine() // IRQ_LORA_RXTOUT_MASK | // IRQ_LORA_HEADER_MASK | // IRQ_LORA_CRCERR_MASK )); - writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); + writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); + _state = S_SCAN; break; } #if DUSB>=1 - if (debug>=1) { - Serial.print(F("RXDONE=")); - Serial.println(ffTime - detTime); + if (( debug>=1 ) && ( pdebug & P_RX )) { + Serial.print(F("RXDONE in dT=")); + Serial.print(ffTime - detTime); + Serial.print(F(": ")); + SerialStat(intr); } #endif @@ -585,7 +651,7 @@ void stateMachine() // if (receivePacket() <= 0) { // read is not successful #if DUSB>=1 - if (debug>=0) { + if (( debug>=0 ) && ( pdebug & P_RX )) { Serial.println(F("sMach:: Error receivePacket")); } #endif @@ -595,6 +661,7 @@ void stateMachine() // if ((_cad) || (_hop)) { _state = S_SCAN; + sf = SF7; cadScanner(); } else { @@ -604,6 +671,7 @@ void stateMachine() writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00); writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); // Reset the interrupt mask + eventTime=micros(); //There was an event for receive _event=0; }// RXDONE @@ -619,20 +687,26 @@ void stateMachine() // For the modem in cad state we reset to SF7 // If a timeout occurs here we reset the cadscanner // + if ((_cad) || (_hop)) { // XXX 01/01/2018 // Set the state to CAD scanning + #if DUSB>=1 - if (debug>=2) { + if (( debug>=1 ) && ( pdebug & P_RX )) { Serial.print(F("RXTOUT:: f=")); Serial.print(ifreq); Serial.print(F(", sf=")); Serial.print(sf); - Serial.print(F(", tim=")); - Serial.println(micros() - detTime); + Serial.print(F(", dT=")); + Serial.print(micros() - detTime); + Serial.print(F(": ")); + SerialStat(intr); } #endif - _state = S_SCAN; + + sf = SF7; cadScanner(); // Start the scanner after RXTOUT + _state = S_SCAN; // New state is scan after RXTOUT }// RXTOUT @@ -642,7 +716,7 @@ void stateMachine() _state = S_RX; // Receive when interrupted rxLoraModem(); } - + eventTime=micros(); //There was an event for receive } else if (intr & IRQ_LORA_HEADER_MASK) { @@ -650,32 +724,41 @@ void stateMachine() // which is normall an indication of RXDONE //writeRegister(REG_IRQ_FLAGS, IRQ_LORA_HEADER_MASK); #if DUSB>=1 - if (debug>=1) { + if (( debug>=2 ) && ( pdebug & P_RX )) { Serial.print(F("RX HEADER:: ")); SerialStat(intr); } #endif - _event=1; + //_event=1; } + // If we did not receive a hard interrupt + // The probably do not do anythings, because in the S_RX + // state there e always comes a RXTOUT or RXDONE interrupt + // + else if (intr == 0x00) { +#if DUSB>=1 + if (( debug>=2) && ( pdebug & P_RX )) { + Serial.print(F("S_RX noINTR:: ")); + SerialStat(intr); + } +#endif + } + // The interrupt received is not RXDONE, RXTOUT or HEADER // therefore we wait. Make sure to clear the interrupt // as HEADER interrupt comes just before RXDONE - else { - //writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00 ); - //writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); - if (_hop) { - _event=1; - } - //_state=S_SCAN; // NONONONONONONONONO do NOT change state + else { #if DUSB>=1 - if (debug>=1) { + if (( debug>=0 ) && ( pdebug & P_RX )) { Serial.print(F("S_RX:: no RXDONE, RXTOUT, HEADER:: ")); SerialStat(intr); } #endif + //writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00 ); + //writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); }// int not RXDONE or RXTOUT - + break; // S_RX @@ -717,8 +800,9 @@ void stateMachine() ); #if DUSB>=2 - if (debug>=0) { + if ( debug>=0 ) { Serial.println(F("S_TX, ")); + SerialStat(intr); } #endif @@ -738,19 +822,23 @@ void stateMachine() case S_TXDONE: if (intr & IRQ_LORA_TXDONE_MASK) { #if DUSB>=1 - Serial.println(F("TXDONE interrupt")); + if (( debug>=0 ) && ( pdebug & P_TX )) { + Serial.println(F("TXDONE interrupt")); + } #endif // After transmission reset to receiver if ((_cad) || (_hop)) { // XXX 26/02 // Set the state to CAD scanning _state = S_SCAN; + sf = SF7; cadScanner(); // Start the scanner after TX cycle } else { _state = S_RX; rxLoraModem(); } - + + _event=0; writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00); writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); // reset interrupt flags #if DUSB>=1 @@ -759,21 +847,20 @@ void stateMachine() if (debug>=2) Serial.flush(); } #endif - _event=0; } // If a soft _event==0 interrupt and no transmission finished: else { #if DUSB>=1 - if (debug>=0) { - Serial.print(F("TXDONE unknown interrupt=")); - Serial.println(intr); - if (debug>=2) Serial.flush(); + if (( debug>=0 ) && ( pdebug & P_TX )) { + Serial.print(F("TXDONE unknown int=")); + SerialStat(intr); } #endif writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00); writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); // reset interrupt flags _event=0; + _state=S_SCAN; } break; // S_TXDONE @@ -792,9 +879,13 @@ void stateMachine() #endif if ((_cad) || (_hop)) { #if DUSB>=1 - if (debug>=1) Serial.println(F("default:: _state set to S_SCAN")); + if (debug>=0) { + Serial.println(F("default:: Unknown _state ")); + SerialStat(intr); + } #endif _state = S_SCAN; + sf = SF7; cadScanner(); _event=1; // XXX Restart the state machine } @@ -806,7 +897,8 @@ void stateMachine() } writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00); writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); // Reset all interrupts - + eventTime=micros(); // Reset event for unkonwn state + break;// default }// switch(_state) diff --git a/ESP-sc-gway/_txRx.ino b/ESP-sc-gway/_txRx.ino index 2fbf044..84b2ab2 100644 --- a/ESP-sc-gway/_txRx.ino +++ b/ESP-sc-gway/_txRx.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-03-09 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many others. @@ -81,7 +81,8 @@ int sendPacket(uint8_t *buf, uint8_t length) #endif return(-1); } - delay(1); + yield(); + // Meta Data sent by server (example) // {"txpk":{"codr":"4/5","data":"YCkEAgIABQABGmIwYX/kSn4Y","freq":868.1,"ipol":true,"modu":"LORA","powe":14,"rfch":0,"size":18,"tmst":1890991792,"datr":"SF7BW125"}} @@ -319,7 +320,7 @@ int buildPacket(uint32_t tmst, uint8_t *buff_up, struct LoraUp LoraUp, bool inte #endif // STATISTICS >= 2 #if DUSB>=1 - if (debug>=1) { + if (( debug>=2 ) && ( pdebug & P_RADIO )){ Serial.print(F("buildPacket:: pRSSI=")); Serial.print(prssi-rssicorr); Serial.print(F(" RSSI: ")); @@ -506,7 +507,7 @@ int buildPacket(uint32_t tmst, uint8_t *buff_up, struct LoraUp LoraUp, bool inte #if DUSB>=1 if (debug>=2) { Serial.print(F("RXPK:: ")); - Serial.println((char *)(buff_up + 12)); // DEBUG: display JSON payload + Serial.println((char *)(buff_up + 12)); // debug: display JSON payload } if (debug>= 2) { Serial.print(F("RXPK:: package length=")); diff --git a/ESP-sc-gway/_utils.ino b/ESP-sc-gway/_utils.ino index a428e7f..ed66956 100644 --- a/ESP-sc-gway/_utils.ino +++ b/ESP-sc-gway/_utils.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-09 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many others. @@ -43,14 +43,14 @@ static void stringTime(time_t t, String& response) { // now() gives seconds since 1970 // as millis() does rotate every 50 days // So we need another timing parameter - time_t eventTime = t; + time_t eTime = t; // Rest is standard - byte _hour = hour(eventTime); - byte _minute = minute(eventTime); - byte _second = second(eventTime); + byte _hour = hour(eTime); + byte _minute = minute(eTime); + byte _second = second(eTime); - switch(weekday(eventTime)) { + switch(weekday(eTime)) { case 1: response += "Sunday "; break; case 2: response += "Monday "; break; case 3: response += "Tuesday "; break; @@ -59,9 +59,9 @@ static void stringTime(time_t t, String& response) { case 6: response += "Friday "; break; case 7: response += "Saturday "; break; } - response += String() + day(eventTime) + "-"; - response += String() + month(eventTime) + "-"; - response += String() + year(eventTime) + " "; + response += String() + day(eTime) + "-"; + response += String() + month(eTime) + "-"; + response += String() + year(eTime) + " "; if (_hour < 10) response += "0"; response += String() + _hour + ":"; @@ -104,17 +104,16 @@ void SerialStat(uint8_t intr) #if DUSB>=1 if (debug>=0) { Serial.print(F("I=")); - //Serial.print(intr,HEX); - if (intr & IRQ_LORA_RXTOUT_MASK) Serial.print(F("RXTOUT")); // 0x80 - if (intr & IRQ_LORA_RXDONE_MASK) Serial.print(F("RXDONE")); // 0x40 - if (intr & IRQ_LORA_CRCERR_MASK) Serial.print(F("CRCERR")); // 0x20 - if (intr & IRQ_LORA_HEADER_MASK) Serial.print(F("HEADER")); // 0x10 - if (intr & IRQ_LORA_TXDONE_MASK) Serial.print(F("TXDONE")); // 0x08 - if (intr & IRQ_LORA_CDDONE_MASK) Serial.print(F("CDDONE")); // 0x04 - if (intr & IRQ_LORA_FHSSCH_MASK) Serial.print(F("FHSSCH")); // 0x02 - if (intr & IRQ_LORA_CDDETD_MASK) Serial.print(F("CDDETD")); // 0x01 - + if (intr & IRQ_LORA_RXTOUT_MASK) Serial.print(F("RXTOUT ")); // 0x80 + if (intr & IRQ_LORA_RXDONE_MASK) Serial.print(F("RXDONE ")); // 0x40 + if (intr & IRQ_LORA_CRCERR_MASK) Serial.print(F("CRCERR ")); // 0x20 + if (intr & IRQ_LORA_HEADER_MASK) Serial.print(F("HEADER ")); // 0x10 + if (intr & IRQ_LORA_TXDONE_MASK) Serial.print(F("TXDONE ")); // 0x08 + if (intr & IRQ_LORA_CDDONE_MASK) Serial.print(F("CDDONE ")); // 0x04 + if (intr & IRQ_LORA_FHSSCH_MASK) Serial.print(F("FHSSCH ")); // 0x02 + if (intr & IRQ_LORA_CDDETD_MASK) Serial.print(F("CDDETD ")); // 0x01 + if (intr == 0x00) Serial.print(F(" -- ")); Serial.print(F(", F=")); @@ -143,12 +142,12 @@ void SerialStat(uint8_t intr) Serial.print(F("TX ")); break; case S_TXDONE: - Serial.print(F("TXDN")); + Serial.print(F("TXDONE")); break; default: Serial.print(F(" -- ")); } - Serial.print(F(", t=")); + Serial.print(F(", eT=")); Serial.print( micros() - eventTime ); Serial.println(); } diff --git a/ESP-sc-gway/_wwwServer.ino b/ESP-sc-gway/_wwwServer.ino index 7fef1b4..f158195 100644 --- a/ESP-sc-gway/_wwwServer.ino +++ b/ESP-sc-gway/_wwwServer.ino @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // based on work done by many people and making use of several libraries. // @@ -130,8 +130,9 @@ static void setVariables(const char *cmd, const char *arg) { _hop=(bool)atoi(arg); if (! _hop) { ifreq=0; - freq=freqs[0]; + freq=freqs[ifreq]; rxLoraModem(); + sf = SF7; cadScanner(); } writeGwayCfg(CONFIGFILE); // Save configuration to file @@ -306,14 +307,14 @@ static void settingsData() response +=""; response +=""; response +=""; - response +=""; - response +=""; + response +=""; + response +=""; response +=""; bg = " background-color: "; bg += ( _cad ? "LightGreen" : "orange" ); response +=""; - response +=""; response +=""; @@ -322,13 +323,13 @@ static void settingsData() bg = " background-color: "; bg += ( _hop ? "LightGreen" : "orange" ); response +=""; - response +=""; response +=""; response +=""; - response +=""; } @@ -341,7 +342,7 @@ static void settingsData() // Channel response +=""; - response +=""; } @@ -353,18 +354,72 @@ static void settingsData() } response +=""; - // Debugging options - response +=""; response +=""; response +=""; response +=""; + + response +=""; + + bg = ( (pdebug & P_SCAN) ? "LightGreen" : "orange" ); + response +=""; + + bg = ( (pdebug & P_CAD) ? "LightGreen" : "orange" ); + response +=""; + bg = ( (pdebug & P_RX) ? "LightGreen" : "orange" ); + response +=""; + + bg = ( (pdebug & P_TX) ? "LightGreen" : "orange" ); + response +=""; + response += ""; + + // Use a second Line + response +=""; + bg = ( (pdebug & P_PRE) ? "LightGreen" : "orange" ); + response +=""; + + bg = ( (pdebug & P_MAIN) ? "LightGreen" : "orange" ); + response +=""; + + bg = ( (pdebug & P_GUI) ? "LightGreen" : "orange" ); + response +=""; + + bg = ( (pdebug & P_RADIO) ? "LightGreen" : "orange" ); + response +=""; + response +=""; +#endif // Serial Debugging - response +=""; //response +=""; @@ -373,7 +428,7 @@ static void settingsData() #if GATEWAYNODE==1 response +=""; - response +=""; @@ -393,7 +448,7 @@ static void settingsData() bg = " background-color: "; bg += ( (gwayConfig.refresh == 1) ? "LightGreen" : "orange" ); response +=""; - response +=""; response +=""; @@ -402,24 +457,24 @@ static void settingsData() // Reset Accesspoint #if WIFIMANAGER==1 - response +=""; #endif // Update Firmware all statistics - response +=""; - response +=""; + response +=""; + response +=""; // Reset all statistics #if STATISTICS >= 1 response +=""; - response +=String() + ""; + response +=String() + ""; response +=""; // Reset response +=""; - response +=String() + ""; + response +=String() + ""; response +=""; #endif @@ -813,11 +868,11 @@ void sendWebPage(const char *cmd, const char *arg) statisticsData(); yield(); // Node statistics sensorData(); yield(); // Display the sensor history, message statistics - systemData(); yield(); // System statistics such as heap etc. + + settingsData(); yield(); // Display web configuration wifiData(); yield(); // WiFI specific parameters - settingsData(); yield(); // Display web configuration - + systemData(); yield(); // System statistics such as heap etc. interruptData(); yield(); // Display interrupts only when debug >= 2 // Close the client connection to server @@ -891,6 +946,14 @@ void setupWWW() statc.resets= 0; writeGwayCfg(CONFIGFILE); +#if STATISTICS >= 3 + statc.sf7_0 = 0; statc.sf7_1 = 0; statc.sf7_2 = 0; + statc.sf8_0 = 0; statc.sf8_1 = 0; statc.sf8_2 = 0; + statc.sf9_0 = 0; statc.sf9_1 = 0; statc.sf9_2 = 0; + statc.sf10_0= 0; statc.sf10_1= 0; statc.sf10_2= 0; + statc.sf11_0= 0; statc.sf11_1= 0; statc.sf11_2= 0; + statc.sf12_0= 0; statc.sf12_1= 0; statc.sf12_2= 0; +#endif #endif #endif server.sendHeader("Location", String("/"), true); @@ -935,6 +998,57 @@ void setupWWW() server.send ( 302, "text/plain", ""); }); + // Set PDEBUG parameter + // + server.on("/PDEBUG=SCAN", []() { // Set debug level 0-2 + pdebug ^= P_SCAN; + writeGwayCfg(CONFIGFILE); // Save configuration to file + server.sendHeader("Location", String("/"), true); + server.send ( 302, "text/plain", ""); + }); + server.on("/PDEBUG=CAD", []() { // Set debug level 0-2 + pdebug ^= P_CAD; + writeGwayCfg(CONFIGFILE); // Save configuration to file + server.sendHeader("Location", String("/"), true); + server.send ( 302, "text/plain", ""); + }); + server.on("/PDEBUG=RX", []() { // Set debug level 0-2 + pdebug ^= P_RX; + writeGwayCfg(CONFIGFILE); // Save configuration to file + server.sendHeader("Location", String("/"), true); + server.send ( 302, "text/plain", ""); + }); + server.on("/PDEBUG=TX", []() { // Set debug level 0-2 + pdebug ^= P_TX; + writeGwayCfg(CONFIGFILE); // Save configuration to file + server.sendHeader("Location", String("/"), true); + server.send ( 302, "text/plain", ""); + }); + server.on("/PDEBUG=PRE", []() { // Set debug level 0-2 + pdebug ^= P_PRE; + writeGwayCfg(CONFIGFILE); // Save configuration to file + server.sendHeader("Location", String("/"), true); + server.send ( 302, "text/plain", ""); + }); + server.on("/PDEBUG=MAIN", []() { // Set debug level 0-2 + pdebug ^= P_MAIN; + writeGwayCfg(CONFIGFILE); // Save configuration to file + server.sendHeader("Location", String("/"), true); + server.send ( 302, "text/plain", ""); + }); + server.on("/PDEBUG=GUI", []() { // Set debug level 0-2 + pdebug ^= P_GUI; + writeGwayCfg(CONFIGFILE); // Save configuration to file + server.sendHeader("Location", String("/"), true); + server.send ( 302, "text/plain", ""); + }); + server.on("/PDEBUG=RADIO", []() { // Set debug level 0-2 + pdebug ^= P_RADIO; + writeGwayCfg(CONFIGFILE); // Save configuration to file + server.sendHeader("Location", String("/"), true); + server.send ( 302, "text/plain", ""); + }); + // Set delay in microseconds server.on("/DELAY=1", []() { diff --git a/ESP-sc-gway/loraFiles.h b/ESP-sc-gway/loraFiles.h index 2a7dd10..3c51cb0 100644 --- a/ESP-sc-gway/loraFiles.h +++ b/ESP-sc-gway/loraFiles.h @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many others. @@ -29,6 +29,18 @@ +// +// Define Pattern debug settings, this allows debugging per +// module rather than per level. See also pdebug. +// +#define P_SCAN 0x01 +#define P_CAD 0x02 +#define P_RX 0x04 +#define P_TX 0x08 +#define P_PRE 0x10 +#define P_MAIN 0x20 +#define P_GUI 0x40 +#define P_RADIO 0x80 // Definition of the configuration record that is read at startup and written // when settings are changed. @@ -47,18 +59,19 @@ struct espGwayConfig { uint8_t ch; // index to freqs array, freqs[ifreq]=868100000 default uint8_t sf; // range from SF7 to SF12 uint8_t debug; // range 0 to 4 + uint8_t pdebug; // pattern debug, uint16_t logFileRec; // Logging File Record number uint16_t logFileNo; // Logging File Number uint16_t logFileNum; // Number of log files bool cad; // is CAD enabled? - bool hop; // Is HOP enabled (Note: Should be disabled) + bool hop; // Is HOP enabled (Note: default be disabled) bool isNode; // Is gateway node enabled bool refresh; // Is WWW browser refresh enabled String ssid; // SSID of the last connected WiFi Network - String pass; // Password + String pass; // Password of WiFi network } gwayConfig; // Define a log record to be written to the log file diff --git a/ESP-sc-gway/loraModem.h b/ESP-sc-gway/loraModem.h index 6901aee..4978f77 100644 --- a/ESP-sc-gway/loraModem.h +++ b/ESP-sc-gway/loraModem.h @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many other contributors. @@ -43,10 +43,10 @@ #define RSSI_WAIT 6 // was 25 // How long will it take when hopping before a CDONE or CDETD value -// should be present and measured. +// is present and can be measured. // -#define EVENT_WAIT 5000 // was 2000 - +#define EVENT_WAIT 25000 // 25 milliseconds before CDDETD +#define DONE_WAIT 1000 // 500 microseconds (1/2000) sec between CDDONE events // Our code should correct the server Tramission delay settings @@ -92,7 +92,7 @@ volatile uint8_t _event=0; uint8_t _rssi; bool _cad= (bool) _CAD; // Set to true for Channel Activity Detection, only when dio 1 connected -bool _hop=false; // experimental; frequency hopping. Only use when dio2 connected +bool _hop= (bool) false;// experimental; frequency hopping. Only use when dio2 connected unsigned long nowTime=0; unsigned long msgTime=0; diff --git a/ESP-sc-gway/oLED.h b/ESP-sc-gway/oLED.h index f2f6d55..b6ea27a 100644 --- a/ESP-sc-gway/oLED.h +++ b/ESP-sc-gway/oLED.h @@ -1,7 +1,7 @@ // 1-channel LoRa Gateway for ESP8266 -// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266 -// Version 5.0.9 -// Date: 2018-04-07 +// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266 +// Version 5.1.0 +// Date: 2018-04-17 // // based on work done by Thomas Telkamp for Raspberry PI 1ch gateway // and many others. diff --git a/README.md b/README.md index 1323074..9dedfe3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Single Channel LoRaWAN Gateway -Version 5.0.8, March 31, 2018 +Version 5.1.0, May 10, 2018 Author: M. Westenberg (mw12554@hotmail.com) Copyright: M. Westenberg (mw12554@hotmail.com) @@ -64,9 +64,17 @@ see nothing on the Serial Monitor. this section. 4. Edit the ESP-sc-gway.h file and adapt the "wpas" structure. `Make sure that the first line of this structure remains empty and put the SSID and Password of your router on the second line of the array. -5. Compile the code and doenload the executable over USB to the gateway. If all is right, you should +5. In the preferences part of the IDE, set the location of your sketch to the place where you put the +sketch on your computer. This will make sure that for example the required libraries that are shipped +with this sketch in the libraries folder can be found by the compiler +6. If not yet done: Load the support for ESP8266 in your IDE. +7. Load the other necessary libraries that are not shipped with this sketch in your IDE. +Goto in the IDE to do so. +- ArduinoJson (version 5.13.1) +- WifiManager (Version 0.12.0 by Tzapu) +8. Compile the code and download the executable over USB to the gateway. If all is right, you should see the gateway starting up on the Serial Monitor. -6. Note the IP address that the device receives from your router. Use that IP address in a browser on +9. Note the IP address that the device receives from your router. Use that IP address in a browser on your computer to connect to the gateway with the browser. Now your gateway should be running. Use the webpage to set "debug" to 1 and you should be able to see packages @@ -163,7 +171,7 @@ gateway will be reduced in CAD mode. ### Over the Air Updates (OTA) -As from version 4.0.6 the gateway allows over the air updated if the setting A_OTA is on. +As from version 4.0.6 the gateway allows over the air updating if the setting A_OTA is on. The over the air software requires once setting of the 4.0.6 version over USB to the gateway, after which the software is (default) enabled for use.
SettingValueSetValueSet
CAD"; + response +=""; response += ( _cad ? "ON" : "OFF" ); response +="
HOP"; + response +=""; response += ( _hop ? "ON" : "OFF" ); response +="
SF Setting"; + response +="
SF Setting"; if (_cad) { response += "AUTO
Channel"; + response +=""; if (_hop) { response += "AUTO
"; - response +="Debug level"; + // Debugging options, only when DUSB is set, otherwise no + // serial activity +#if DUSB>=1 + response +="
Debug level"; response +=debug; response +="
Debug pattern"; + response +=""; + response +=""; + response +=""; + response +=""; + response +=""; + response +=""; + response +=""; + response +="
"; + response +=""; + response +=""; + response +=""; + response +=""; + response +=""; + response +=""; + response +=""; + response +="
"; - response +="Usb Debug"; + response +="
Usb Debug"; response +=DUSB; response +="
Framecounter Internal Sensor"; + response +=""; response +=frameCount; response +=""; response +="
WWW Refresh"; + response +=""; response += ( (gwayConfig.refresh == 1) ? "ON" : "OFF" ); response +="
"; + response +="
"; response +="Click here to reset accesspoint
"; response +="
Update Firmware
Update Firmware
Statistics"+statc.resets+""+statc.resets+"
Boots and Resets"+gwayConfig.boots+""+gwayConfig.boots+"