Version 5.1.1: Button on the GUI to download the LOGFILES of all previous messages, Enable SPIFFS filesystem formatting from the GUI, Bug fixes

pull/29/head
platenspeler 2018-05-22 22:58:26 +02:00
rodzic 9aebd1258e
commit 9788e54d19
17 zmienionych plików z 306 dodań i 193 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0 H
// Date: 2018-05-03
// Version 5.1.1 H
// Date: 2018-05-17
//
// 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.1.0.H; 180503a"
#define VERSION "V.5.1.1.H; 180517a"
// This value of DEBUG determines whether some parts of code get compiled.
// Also this is the initial value of debug parameter.
@ -29,13 +29,14 @@
// Debug message will be put on Serial is this one is set.
// If set to 0, not USB Serial prints are done
// Set to 1 it will prin all user level messages (with correct debug set)
// Set to 1 it will prinr all user level messages (with correct debug set)
// If set to 2 it will also print interrupt messages (not recommended)
#define DUSB 1
// Define whether we should do a formatting of SPIFFS when starting the gateway
// This is usually a good idea if the webserver is interrupted halfway a writing
// operation.
// Normally, value 1 is a good default.
#define SPIFF_FORMAT 0
// The spreading factor is the most important parameter to set for a single channel
@ -60,8 +61,8 @@
// A_SERVER determines whether or not the admin webpage is included in the sketch.
// Normally, leave it in!
#define A_SERVER 1 // Define local WebServer only if this define is set
#define A_REFRESH 1 // Will the webserver refresh or not?
#define A_SERVERPORT 80 // local webserver port
#define A_REFRESH 1 // Allow the webserver refresh or not?
#define A_SERVERPORT 80 // Local webserver port (normally 80)
#define A_MAXBUFSIZE 192 // Must be larger than 128, but small enough to work
// Definitions for over the air updates. At the moment we support OTA with IDE
@ -84,6 +85,7 @@
// 0= No statistics
// 1= Keep track of messages statistics, number determined by MAX_STAT
// 2= Option 1 + Keep track of messages received PER each SF (default)
// 3= See Option 2, but with extra channel info (Do not use when no Hopping is done)
#define STATISTICS 3
// Maximum number of statistics records gathered. 20 is a good maximum (memory intensive)
@ -128,7 +130,7 @@
#define MUTEX 0
// Define if OLED Display is connected to I2C bus. Note that defining an OLED display does not
// impact perfoamce very much, certainly if no OLED is connected. Wrong OLED will not show
// impact performance very much, certainly if no OLED is connected. Wrong OLED will not show
// sensible results on display
// OLED==0; No OLED display connected
// OLED==1; 0.9 Oled Screen based on SSD1306
@ -155,6 +157,7 @@
//
#define STAT_LOG 1
// Name of he configfile in SPIFFs filesystem
// In this file we store the configuration and other relevant info that should
// survive a reboot of the gateway
@ -180,28 +183,29 @@
// If not, make sure that you do not defined these, which will save CPU time
// Port is UDP port in this program
//
// Default for testing: Switch off
// Default for testing: Switched off
#define _THINGPORT 57084 // dash.westenberg.org:8057
#define _THINGSERVER "westenberg.org" // Server URL of the LoRa-udp.js handler
// Gateway Ident definitions
#define _DESCRIPTION "ESP Gateway"
#define _EMAIL "mw12554@hotmail.com"
#define _DESCRIPTION "ESP Gateway" // Name of the gateway
#define _EMAIL "mw12554@hotmail.com" // Owner
#define _PLATFORM "ESP8266"
#define _LAT 52
#define _LON 5.9
#define _ALT 1
#define _LAT 52.237367
#define _LON 5.978654
#define _ALT 14 // Altitude
// ntp
// Please add daylight saving time to NTP_TIMEZONES when desired
#define NTP_TIMESERVER "nl.pool.ntp.org" // Country and region specific
#define NTP_TIMEZONES 1 // How far is our Timezone from UTC (excl daylight saving/summer time)
#define NTP_TIMEZONES 2 // How far is our Timezone from UTC (excl daylight saving/summer time)
#define SECS_IN_HOUR 3600
#define NTP_INTR 0 // Do NTP processing with interrupts or in loop();
#if GATEWAYNODE==1
#define _DEVADDR { 0x26, 0x01, 0x00, 0x00 }
#define _APPSKEY { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
#define _NWKSKEY { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
#define _DEVADDR { 0x26, 0x01, 0x15, 0x3D }
#define _APPSKEY { 0x02, 0x02, 0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x54, 0x68, 0x69, 0x6E, 0x67, 0x73, 0x34, 0x55 }
#define _NWKSKEY { 0x54, 0x68, 0x69, 0x6E, 0x67, 0x73, 0x34, 0x55, 0x54, 0x68, 0x69, 0x6E, 0x67, 0x73, 0x34, 0x55 }
#define _SENSOR_INTERVAL 300
#endif
@ -261,8 +265,13 @@ struct wpas {
//
wpas wpa[] = {
{ "" , "" }, // Reserved for WiFi Manager
{ "aap", "noot" },
{ "mies", "teun" }
{ "platenspeler", "maanlama@16" },
// { "bushhouse", "bush1967" },
// { "Maarten-in", "apeldoorn47" },
// { "Livebox-0e0d", "E2D92F37634C512F712E3DCC1E"},
// { "GLGK_Public","draadloosinternet" },
{ "UPC0207874","XBQBUXTU" },
{ "OnePlus2", "maanlama@16" }
};
// For asserting and testing the following defines are used.

Wyświetl plik

@ -1,11 +1,10 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
// Author: Maarten Westenberg (mw12554@hotmail.com)
//
// based on work done by Thomas Telkamp for Raspberry PI 1-ch gateway
// and many others.
// Based on work done by Thomas Telkamp for Raspberry PI 1-ch gateway and many others.
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the MIT License
@ -25,12 +24,9 @@
//
// ----------------------------------------------------------------------------------------
//
#include "ESP-sc-gway.h" // This file contains configuration of GWay
#include "ESP-sc-gway.h"
// This file contains configuration of GWay
#include <Esp.h>
#include <Esp.h> // ESP8266 specific IDE functions
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
@ -41,7 +37,7 @@
#include <cstring>
#include <string> // C++ specifix string functions
#include <SPI.h>
#include <SPI.h> // For the RFM95 bus
#include <TimeLib.h> // http://playground.arduino.cc/code/time
#include <DNSServer.h> // Local DNSserver
#include <ArduinoJson.h>
@ -362,7 +358,8 @@ time_t getNtpTime()
if (!sendNtpRequest(ntpServer)) // Send the request for new time
{
if (debug>0) Serial.println(F("sendNtpRequest failed"));
if (( debug>=0 ) && ( pdebug & P_MAIN ))
Serial.println(F("sendNtpRequest failed"));
return(0);
}
@ -402,7 +399,7 @@ time_t getNtpTime()
gwayConfig.ntpErr++;
gwayConfig.ntpErrTime = now();
#if DUSB>=1
if (debug>0) {
if (( debug>=0 ) && ( pdebug & P_MAIN )) {
Serial.println(F("getNtpTime:: read failed"));
}
#endif
@ -474,11 +471,13 @@ int WlanReadWpa() {
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();
if ( debug >=0 ) && ( pdebug & P_MAIN )) {
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);
@ -550,7 +549,7 @@ int WlanConnect(int maxTry) {
Serial.print(j);
Serial.print(F(". WiFi connect SSID="));
Serial.print(ssid);
if (debug>=1) {
if (( debug>=1 ) && ( pdebug & P_MAIN )) {
Serial.print(F(", pass="));
Serial.print(password);
}
@ -576,7 +575,8 @@ int WlanConnect(int maxTry) {
agains++;
delay(agains*500);
#if DUSB>=1
if (debug>=0) Serial.print(".");
if (( debug>=0 ) && ( pdebug & P_MAIN ))
Serial.print(".");
#endif
}
@ -584,14 +584,15 @@ int WlanConnect(int maxTry) {
switch (WiFi.status()) {
case WL_CONNECTED:
#if DUSB>=1
if (debug>=0)
if (( debug>=0 ) && ( pdebug & P_MAIN ))
Serial.println(F("WlanConnect:: CONNECTED")); // 3
#endif
return(1);
break;
case WL_IDLE_STATUS:
#if DUSB>=1
Serial.println(F("WlanConnect:: IDLE")); // 0
if (( debug>=0 ) && ( pdebug & P_MAIN ))
Serial.println(F("WlanConnect:: IDLE")); // 0
#endif
break;
case WL_NO_SSID_AVAIL:
@ -601,28 +602,34 @@ int WlanConnect(int maxTry) {
break;
case WL_CONNECT_FAILED:
#if DUSB>=1
Serial.println(F("WlanConnect:: FAILED")); // 4
if (( debug>=0 ) && ( pdebug & P_MAIN ))
Serial.println(F("WlanConnect:: FAILED")); // 4
#endif
break;
case WL_DISCONNECTED:
#if DUSB>=1
Serial.println(F("WlanConnect:: DISCONNECTED")); // 6
if (( debug>=0 ) && ( pdebug & P_MAIN ))
Serial.println(F("WlanConnect:: DISCONNECTED")); // 6
#endif
break;
case WL_SCAN_COMPLETED:
#if DUSB>=1
Serial.println(F("WlanConnect:: SCAN COMPLETE")); // 2
if (( debug>=0 ) && ( pdebug & P_MAIN ))
Serial.println(F("WlanConnect:: SCAN COMPLETE")); // 2
#endif
break;
case WL_CONNECTION_LOST:
#if DUSB>=1
Serial.println(F("WlanConnect:: LOST")); // 5
if (( debug>=0 ) && ( pdebug & P_MAIN ))
Serial.println(F("WlanConnect:: LOST")); // 5
#endif
break;
default:
#if DUSB>=1
Serial.print(F("WlanConnect:: code="));
Serial.println(WiFi.status());
if (( debug>=0 ) && ( pdebug & P_MAIN )) {
Serial.print(F("WlanConnect:: code="));
Serial.println(WiFi.status());
}
#endif
break;
}
@ -666,7 +673,7 @@ int WlanConnect(int maxTry) {
WlanWriteWpa((char *)sta_conf.ssid, (char *)sta_conf.password);
#else
#if DUSB>=1
if (debug>=0) {
if (( debug>=0) && ( pdebug & P_MAIN )) {
Serial.println(F("WlanConnect:: Not connected after all"));
Serial.print(F("WLAN retry="));
Serial.print(i);
@ -1442,7 +1449,7 @@ void loop ()
// 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
// The interval is in seconds (about 15 seconds) as this re-init
// is a heavy operation.
// SO it will kick in if there are not many messages for the gatway.
// Note: Be carefull that it does not happen too often in normal operation.
@ -1452,7 +1459,7 @@ void loop ()
{
#if DUSB>=1
if (( debug>=1 ) && ( pdebug & P_MAIN )) {
Serial.print("REINIT: ");
Serial.print("REINIT:: ");
Serial.print( _MSG_INTERVAL );
Serial.print(F(" "));
SerialStat(0);
@ -1544,14 +1551,14 @@ void loop ()
if ((nowSeconds - statTime) >= _STAT_INTERVAL) { // Wake up every xx seconds
#if DUSB>=1
if (( debug>=1 ) && ( pdebug & P_MAIN )) {
Serial.print(F("STAT <"));
Serial.print(F("STAT:: ..."));
Serial.flush();
}
#endif
sendstat(); // Show the status message and send to server
#if DUSB>=1
if (( debug>=2 ) && ( pdebug & P_MAIN )) {
Serial.println(F(">"));
if (( debug>=1 ) && ( pdebug & P_MAIN )) {
Serial.println(F("done"));
if (debug>=2) Serial.flush();
}
#endif
@ -1587,7 +1594,7 @@ void loop ()
nowSeconds = now();
if ((nowSeconds - pulltime) >= _PULL_INTERVAL) { // Wake up every xx seconds
#if DUSB>=1
if (debug>=2) {
if (( debug>=2) && ( pdebug & P_MAIN )) {
Serial.print(F("PULL <"));
if (debug>=1) Serial.flush();
}

Wyświetl plik

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2016,2017 Maarten Westenberg (mw12554@hotmail.com)
Copyright (c) 2016, 2017, 2018 Maarten Westenberg (mw12554@hotmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// Based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.
@ -265,12 +265,12 @@ int writeConfig(const char *fn, struct espGwayConfig *c) {
// ----------------------------------------------------------------------------
void addLog(const unsigned char * line, int cnt)
{
#if STAT_LOG == 1
#if STAT_LOG==1
char fn[16];
if (gwayConfig.logFileRec > LOGFILEREC) { // Have to make define for this
gwayConfig.logFileRec = 0; // INn new logFile start ith record 0
gwayConfig.logFileNo++; // Increase file ID
gwayConfig.logFileNo++; // Increase file ID
gwayConfig.logFileNum++; // Increase number of log files
}
gwayConfig.logFileRec++;
@ -291,7 +291,7 @@ void addLog(const unsigned char * line, int cnt)
sprintf(fn,"/log-%d", gwayConfig.logFileNo);
// If there is no SPIFFS, Error
// Make sure to write the config record also
// Make sure to write the config record/line also
if (!SPIFFS.exists(fn)) {
#if DUSB>=1
if (( debug >= 1 ) && ( pdebug & P_GUI )) {
@ -315,7 +315,7 @@ void addLog(const unsigned char * line, int cnt)
}
#if DUSB>=1
if (( debug>=1 ) && ( pdebug & P_RX )) {
if (( debug>=1 ) && ( pdebug & P_GUI )) {
Serial.print(F("addLog:: fileno="));
Serial.print(gwayConfig.logFileNo);
Serial.print(F(", rec="));
@ -332,9 +332,15 @@ void addLog(const unsigned char * line, int cnt)
Serial.println();
}
#endif //DUSB
f.write(line, cnt); // write/append the line to the file
int i;
for (i=0; i< 12; i++) { // The first 12 bytes contain non printble characters
// f.print(line[i],HEX);
// f.print(' ');
}
f.write(&line[i], cnt-12); // write/append the line to the file
f.print('\n');
f.close(); // Close the file after appending to it
f.close(); // Close the file after appending to it
#endif //STAT_LOG
}

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.
@ -305,19 +305,55 @@ void opmode(uint8_t mode)
// receiver frequency is determined by ifreq index like so: freqs[ifreq]
// ----------------------------------------------------------------------------
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
setRate(sf, 0x40);
// 1. Set radio to standby
opmode(OPMODE_STANDBY);
// Be aware that micros() has increased significantly from calling
// the hop function until printed below
//
// 3. Set frequency based on value in freq
ifreq = (ifreq + 1) % NUM_HOPS ; // Increment the freq round robin
freq = freqs[ifreq];
setFreq(freqs[ifreq]);
// 4. Set spreading Factor
sf = SF7; // Starting the new frequency
setRate(sf, 0x40); // set the sf to SF7
// Low Noise Amplifier used in receiver
writeRegister(REG_LNA, (uint8_t) LNA_MAX_GAIN); // 0x0C, 0x23
// 7. set sync word
writeRegister(REG_SYNC_WORD, (uint8_t) 0x34); // set 0x39 to 0x34 LORA_MAC_PREAMBLE
// prevent node to node communication
writeRegister(REG_INVERTIQ,0x27); // 0x33, 0x27; to reset from TX
// Max Payload length is dependent on 256 byte buffer. At startup TX starts at
// 0x80 and RX at 0x00. RX therefore maximized at 128 Bytes
writeRegister(REG_MAX_PAYLOAD_LENGTH,MAX_PAYLOAD_LENGTH); // set 0x23 to 0x80==128 bytes
writeRegister(REG_PAYLOAD_LENGTH,PAYLOAD_LENGTH); // 0x22, 0x40==64Byte long
writeRegister(REG_FIFO_ADDR_PTR, (uint8_t) readRegister(REG_FIFO_RX_BASE_AD)); // set reg 0x0D to 0x0F
writeRegister(REG_HOP_PERIOD,0x00); // reg 0x24, set to 0x00
// 5. Config PA Ramp up time // set reg 0x0A
writeRegister(REG_PARAMP, (readRegister(REG_PARAMP) & 0xF0) | 0x08); // set PA ramp-up time 50 uSec
// Set 0x4D PADAC for SX1276 ; XXX register is 0x5a for sx1272
writeRegister(REG_PADAC_SX1276, 0x84); // set 0x4D (PADAC) to 0x84
//writeRegister(REG_PADAC, readRegister(REG_PADAC) | 0x4);
// 8. Reset interrupt Mask, enable all interrupts
writeRegister(REG_IRQ_FLAGS_MASK, 0x00);
// 9. clear all radio IRQ flags
writeRegister(REG_IRQ_FLAGS, 0xFF);
// Be aware that micros() has increased significantly from calling
// the hop function until printed below
//
#if DUSB>=1
if (debug>=2) {
if (debug>=2) {
Serial.print(F("hop:: freq="));
Serial.print(ifreq);
Serial.print(F(", sf="));
@ -325,10 +361,10 @@ void hop() {
Serial.print(F(", tim="));
Serial.print(micros() - hopTime);
Serial.println();
}
}
#endif
// Remember the last time we hop
hopTime = micros(); // At what time did we hop
// Remember the last time we hop
hopTime = micros(); // At what time did we hop
}
@ -678,12 +714,7 @@ void rxLoraModem()
//opmode(OPMODE_LORA); // Is already so
// 2. Put the radio in sleep mode
//if (_hop) {
// opmode(OPMODE_SLEEP); // power save, and enable switch FSK/OOK ro LORA
//}
//else {
opmode(OPMODE_STANDBY); // CAD set 0x01 to 0x00
//}
opmode(OPMODE_STANDBY); // CAD set 0x01 to 0x00
// 3. Set frequency based on value in freq
setFreq(freqs[ifreq]); // set to 868.1MHz
@ -741,6 +772,7 @@ void rxLoraModem()
else {
// Set Continous Receive Mode, usefull if we stay on one SF
_state= S_RX;
if (_hop) Serial.println(F("rxLoraModem:: ERROR continuous receive in hop mode"));
opmode(OPMODE_RX); // 0x80 | 0x05 (listen)
}
@ -781,7 +813,7 @@ void cadScanner()
// listen to LORA_MAC_PREAMBLE
writeRegister(REG_SYNC_WORD, (uint8_t) 0x34); // set reg 0x39 to 0x34
// Set the interrupts we want top listen to
// Set the interrupts we want to listen to
writeRegister(REG_DIO_MAPPING_1, (uint8_t)(
MAP_DIO0_LORA_CADDONE |
MAP_DIO1_LORA_CADDETECT |

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.5
// Date: 2018-05-17
//
//
// All rights reserved. This program and the accompanying materials

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg
// Verison 5.1.0
// Date: 2018-04-17
// Verison 5.1.1
// Date: 2018-05-17
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the MIT License

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg
// Verison 5.1.0
// Date: 2018-04-17
// Verison 5.1.1
// Date: 2018-05-17
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the MIT License

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-25
// Version 5.1.1
// Date: 2018-05-25
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.
@ -115,30 +115,22 @@ void stateMachine()
//
// So we init the wait time for RXDONE based on the current SF.
// As for highter CF it takes longer to receive symbols
// Assume symbols in SF8 take twice the time of SF7
//
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;
case SF7: break;
case SF8: doneWait *= 2; 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();
if (( debug>=0 ) && ( pdebug & P_PRE )) {
Serial.print(F("PRE:: DEF set"));
Serial.println();
}
#endif
}
@ -153,7 +145,7 @@ void stateMachine()
_state = S_SCAN;
hop(); // increment ifreq = (ifreq + 1) % NUM_HOPS ;
cadScanner(); // Reset to initial SF, leave frequency "freqs[ifreq]"
rxLoraModem();
//rxLoraModem();
#if DUSB>=1
if (( debug >= 1 ) && ( pdebug & P_PRE )) {
Serial.print(F("DONE:: "));
@ -164,9 +156,8 @@ void stateMachine()
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 timeout occurs and still no _event, then hop
// and start scanning again
//
if ((micros() - eventTime) > eventWait )
{
@ -188,7 +179,6 @@ void stateMachine()
// 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="));
@ -199,20 +189,21 @@ void stateMachine()
SerialStat(intr);
}
#endif
} // if SCAN or CAD
// else, S_RX of S_TX for example
else {
yield();
//yield(); // May take too much time for RX
} // else S_RX or S_TX, TXDONE
yield();
}// 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
@ -251,13 +242,12 @@ void stateMachine()
if (intr & IRQ_LORA_CDDETD_MASK) {
_state = S_RX; // Set state to receiving
opmode(OPMODE_RX_SINGLE); // set reg 0x01 to 0x06
// Set RXDONE interrupt to dio0, RXTOUT to dio1
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
@ -267,32 +257,34 @@ void stateMachine()
IRQ_LORA_RXTOUT_MASK |
IRQ_LORA_HEADER_MASK |
IRQ_LORA_CRCERR_MASK));
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
//if (_cad) // XXX 180520 make sure we start reading asap in hop
// 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 as we have an interrupt
// XXX IRQ writeregister was here May 11
detTime = micros();
detTime = micros(); // mark time that preamble detected
#if DUSB>=1
if (( debug>=1 ) && ( pdebug & P_SCAN )) {
if (( debug>=1 ) && ( pdebug & P_SCAN )) {
Serial.print(F("SCAN:: "));
SerialStat(intr);
}
#endif
writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF ); // reset all interrupt flags
opmode(OPMODE_RX_SINGLE); // set reg 0x01 to 0x06 for receiving
}//if
// CDDONE
// We received a CDDONE int telling us that we received a message on this
// frequency and possibly on one of its SF.
// frequency and possibly on one of its SF. Only when the incoming message
// matches the SF then also CDDETD is raised.
// If so, we switch to CAD state where we will wait for CDDETD event.
//
else if (intr & IRQ_LORA_CDDONE_MASK) {
@ -403,6 +395,7 @@ void stateMachine()
// Intr=IRQ_LORA_CDDETD_MASK
// We have to set the sf based on a strong RSSI for this channel
// Also we set the state to S_RX and start receiving the message
//
if (intr & IRQ_LORA_CDDETD_MASK) {
@ -414,7 +407,10 @@ void stateMachine()
MAP_DIO3_LORA_CRC ));
// Accept no interrupts except RXDONE or RXTOUT
_event=0; // if CDECT, state=S_RX so we wait for intr
_event=0;
// if CDECT, make state S_RX so we wait for RXDONE intr
writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) ~(
IRQ_LORA_RXDONE_MASK |
IRQ_LORA_RXTOUT_MASK |
@ -423,10 +419,11 @@ 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, (uint8_t) 0xFF ); // XXX 180326, reset all CAD Detect interrupt flags
//writeRegister(REG_IRQ_FLAGS, IRQ_LORA_CDDETD_MASK | IRQ_LORA_RXDONE_MASK);
// If we want to reset CRC, HEADER and RXTOUT flags as well
writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF ); // XXX 180326, reset all CAD Detect interrupt flags
_state = S_RX; // Set state to start receiving
//_state = S_RX; // XXX 180521 Set state to start receiving
opmode(OPMODE_RX_SINGLE); // set reg 0x01 to 0x06, initiate READ
delayMicroseconds( RSSI_WAIT ); // Wait some microseconds less
@ -436,13 +433,13 @@ void stateMachine()
detTime = micros();
#if DUSB>=1
if (( debug>=1 ) && ( pdebug & P_CAD )) {
if (( debug>=2 ) && ( pdebug & P_CAD )) {
Serial.print(F("CAD:: "));
SerialStat(intr);
}
#endif
_state = S_RX; // Set state to start receiving
}// CDDETD
// Intr == CADDONE
@ -539,7 +536,7 @@ void stateMachine()
// If we receive an RXDONE interrupt on dio0 with state==S_RX
// So we should handle the received message
// Else if it is RXTOUT interrupt
// So we handle this
// So we handle this, and get modem out of standby
// Else
// Go back to SCAN
//
@ -675,40 +672,37 @@ void stateMachine()
_event=0;
}// RXDONE
// RX TIMEOUT: We did receive message receive timeout
// RXOUT:
// We did receive message receive timeout
// This is the most common event in hop mode, possibly due to the fact
// that receiving has started too late in the middle of a message
// (according to the documentation). So is there a way to start receiving
// immediately without delay.
//
else if (intr & IRQ_LORA_RXTOUT_MASK) {
// Make sure we reset all interrupts//
// Make sure we reset all interrupts
// and get back to scanning
_event=0; // Is set by interrupt handlers
writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00 );
writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); // reset all interrupts
// For the modem in cad state we reset to SF7
// If RXTOUT we put the modem in cad state and reset to SF7
// If a timeout occurs here we reset the cadscanner
//
if ((_cad) || (_hop)) { // XXX 01/01/2018
if ((_cad) || (_hop)) {
// Set the state to CAD scanning
#if DUSB>=1
if (( debug>=1 ) && ( pdebug & P_RX )) {
Serial.print(F("RXTOUT:: f="));
Serial.print(ifreq);
Serial.print(F(", sf="));
Serial.print(sf);
Serial.print(F(", dT="));
Serial.print(micros() - detTime);
Serial.print(F(": "));
Serial.print(F("RXTOUT:: "));
SerialStat(intr);
}
#endif
sf = SF7;
cadScanner(); // Start the scanner after RXTOUT
_state = S_SCAN; // New state is scan after RXTOUT
_state = S_SCAN; // New state is scan
}// RXTOUT
}
// If not in cad mode we are in single channel single sf mode.
//
@ -716,8 +710,10 @@ void stateMachine()
_state = S_RX; // Receive when interrupted
rxLoraModem();
}
eventTime=micros(); //There was an event for receive
}
eventTime=micros(); //There was an event for receive
}// RXTOUT
else if (intr & IRQ_LORA_HEADER_MASK) {
// This interrupt means we received an header successfully
@ -872,7 +868,7 @@ void stateMachine()
// make sure that we pick up next interrupt
default:
#if DUSB>=1
if (debug >= 0) {
if (( debug>=0) && ( pdebug & P_PRE )) {
Serial.print("ERR state=");
Serial.println(_state);
}

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.
@ -528,11 +528,9 @@ int buildPacket(uint32_t tmst, uint8_t *buff_up, struct LoraUp LoraUp, bool inte
// Receive a LoRa message and fill the buff_up char buffer.
// returns values:
// - returns the length of string returned in buff_up
// - returns -1 when no message arrived.
// - returns -1 or -2 when no message arrived, depending connection.
//
// This is the "highlevel" function called by loop()
// _state is S_RX when starting and
// _state is S_STANDBY when leaving function
// ----------------------------------------------------------------------------
int receivePacket()
{

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// based on work done by many people and making use of several libraries.
//
@ -53,35 +53,88 @@ static void printIP(IPAddress ipa, const char sep, String& response)
// ================================================================================
// WEBSERVER DECLARATIONS
// ================================================================================
// None at the moment
// ================================================================================
// WEBSERVER FUNCTIONS
// ================================================================================
// ----------------------------------------------------------------------------
// WWWFILES
// This function will open a pop-up in the browser and then
// display the contents of a file in that window
// Output is sent to server.sendContent()
// ----------------------------------------------------------------------------
void wwwFile(String fn) {
if (!SPIFFS.exists(fn)) {
#if DUSB>=1
Serial.print(F("wwwButtons:: ERROR: file not found="));
Serial.println(fn);
#endif
return;
}
#if DUSB>=1
else {
Serial.print(F("wwwButtons:: File existist= "));
Serial.println(fn);
}
#endif
#if DUSB>=1
File f = SPIFFS.open(fn, "r"); // Open the file for reading
int j;
for (j=0; j<LOGFILEREC; j++) {
String s=f.readStringUntil('\n');
if (s.length() == 0) {
Serial.print(F("wwwFile:: String length 0"));
break;
}
server.sendContent(s.substring(12)); // Skip the first 12 Gateway specific binary characters
server.sendContent("\n");
yield();
}
#endif
}
// ----------------------------------------------------------------------------
// Button function Stat, display statistics
// ----------------------------------------------------------------------------
void buttonStat()
{
Serial.print(F("Log"));
Serial.println();
printLog();
String response = "";
openWebPage();
wwwButtons();
response += "Statistics";
response+= "alert('Log');";
server.sendContent(response);
}
// ----------------------------------------------------------------------------
// Button gunction log displays logfiles and lets the user select one.
// Button gunction Log displays logfiles.
// ----------------------------------------------------------------------------
void buttonLog()
{
Serial.print(F("Log"));
Serial.println();
//alert("Print log on USB port. This may take a while");
printLog();
String response = "";
response+= "alert('Log');";
String fn = "";
int i = 0;
while (i< LOGFILEMAX ) {
fn = "/log-" + String(gwayConfig.logFileNo - i);
wwwFile(fn); // Display the file contents in the browser
i++;
}
server.sendContent(response);
}
@ -93,8 +146,10 @@ void buttonLog()
static void wwwButtons()
{
String response = "";
response += "<a href=\"STAT\"><button type=\"button\">Stat</button></a>";
response += "<a href=\"LOG\"><button type=\"button\">Log</button></a>";
response += "<a href=\"STAT\" download><button type=\"button\">Stat</button></a>";
response += "<a href=\"LOG\" download><button type=\"button\">Log</button></a>";
server.sendContent(response); // Send to the screen
}
@ -466,6 +521,11 @@ static void settingsData()
response +="<tr><td class=\"cell\">Update Firmware</td><td colspan=\"2\"></td>";
response +="<td class=\"cell\" colspan=\"2\" class=\"cell\"><a href=\"/UPDATE=1\"><button>UPDATE</button></a></td></tr>";
// Format the Filesystem
response +="<tr><td class=\"cell\">Format SPIFFS</td>";
response +=String() + "<td class=\"cell\" colspan=\"2\" >"+""+"</td>";
response +="<td colspan=\"2\" class=\"cell\"><a href=\"/FORMAT\"><button>FORMAT</button></a></td></tr>";
// Reset all statistics
#if STATISTICS >= 1
response +="<tr><td class=\"cell\">Statistics</td>";
@ -926,6 +986,13 @@ void setupWWW()
server.send ( 302, "text/plain", "");
});
// Format the filesystem
server.on("/FORMAT", []() {
Serial.print(F("FORMAT ..."));
SPIFFS.format(); // Normally disabled. Enable only when SPIFFS corrupt
Serial.println(F("DONE"));
});
// Reset the statistics
server.on("/RESET", []() {
@ -1182,14 +1249,13 @@ void setupWWW()
// Display Statistics
server.on("/STAT", []() {
buttonStat();
server.sendHeader("Location", String("/"), true);
buttonStat();
server.send ( 302, "text/plain", "");
});
server.on("/LOG", []() {
buttonLog();
server.sendHeader("Location", String("/"), true);
buttonLog();
server.send ( 302, "text/plain", "");
});

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many other contributors.
@ -45,7 +45,7 @@
// How long will it take when hopping before a CDONE or CDETD value
// is present and can be measured.
//
#define EVENT_WAIT 25000 // 25 milliseconds before CDDETD
#define EVENT_WAIT 20000 // XXX 180520 was 25 milliseconds before CDDETD timeout
#define DONE_WAIT 1000 // 500 microseconds (1/2000) sec between CDDONE events
@ -371,7 +371,6 @@ struct LoraUp {
// FSK specific
#define MAP_DIO0_FSK_READY 0x00 // 00------ (packet sent / payload ready)
#define MAP_DIO1_FSK_NOP 0x30 // --11----
#define MAP_DIO2_FSK_TXNOP 0x04 // ----01--
#define MAP_DIO2_FSK_TIMEOUT 0x08 // ----10--
@ -380,12 +379,12 @@ struct LoraUp {
// Bits masking the corresponding IRQs from the radio
#define IRQ_LORA_RXTOUT_MASK 0x80 // RXTOUT
#define IRQ_LORA_RXDONE_MASK 0x40 // RXDONE after receiving the header and CRC, we receive payload part
#define IRQ_LORA_CRCERR_MASK 0x20
#define IRQ_LORA_CRCERR_MASK 0x20 // CRC error detected. Note that RXDONE will also be set
#define IRQ_LORA_HEADER_MASK 0x10 // valid HEADER mask. This interrupt is first when receiving a message
#define IRQ_LORA_TXDONE_MASK 0x08
#define IRQ_LORA_TXDONE_MASK 0x08 // End of TRansmission
#define IRQ_LORA_CDDONE_MASK 0x04 // CDDONE
#define IRQ_LORA_FHSSCH_MASK 0x02
#define IRQ_LORA_CDDETD_MASK 0x01
#define IRQ_LORA_CDDETD_MASK 0x01 // Detect preamble channel
// ----------------------------------------

Wyświetl plik

@ -1,7 +1,7 @@
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017, 2018 Maarten Westenberg version for ESP8266
// Version 5.1.0
// Date: 2018-04-17
// Version 5.1.1
// Date: 2018-05-17
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.