Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for EU863-870, US902-928 & AU925-928 frequency plans. #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions ESP-sc-gway/ESP-sc-gway.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
// This value of DEBUG determines whether some parts of code get compiled.
// Also this is the initial value of debug parameter.
// The value can be changed using the admin webserver
// For operational use, set initial DEBUG vaulue 0
// For operational use, set initial DEBUG value 0
#define DEBUG 0

// 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)
// Debug messages will be put on Serial if this one is set.
// If set to 0, no USB Serial prints are done
// Set to 1 it will print all user level messages (with correct debug set)
// If set to 2 it will also print interrupt messages (not recommended)
#define DUSB 1

Expand All @@ -38,6 +38,11 @@
// operation.
#define SPIFF_FORMAT 0

// Define the frequency band the gateway will listen on. Valid options are
// EU863_870 (Europe), US902_928 (North America) & AU925_928 (Australia).
// See https://www.thethingsnetwork.org/docs/lorawan/frequency-plans.html
#define EU863_870

// The spreading factor is the most important parameter to set for a single channel
// gateway. It specifies the speed/datarate in which the gateway and node communicate.
// As the name says, in principle the single channel gateway listens to one channel/frequency
Expand All @@ -52,7 +57,7 @@
// factor accordingly. If set to 1 we will use this function which means the
// 1-channel gateway will become even more versatile. If set to 0 we will use the
// continuous listen mode.
// Using this function means that we HAVE to use more dio pins on the RFM95/sx1276
// Using this function means that we HAVE to use more dio pins on the RFM95/SX1276
// device and also connect enable dio1 to detect this state.
#define _CAD 1

Expand All @@ -65,7 +70,7 @@
#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
// Make sure that tou have installed Python version 2.7 and have Bonjour in your network.
// Make sure that you have installed Python version 2.7 and have Bonjour in your network.
// Bonjour is included in iTunes (which is free) and OTA is recommended to install
// the firmware on your router witout having to be really close to the gateway and
// connect with USB.
Expand Down Expand Up @@ -119,7 +124,7 @@
#define _CHECK_MIC 0

// This section defines whether we use the gateway as a repeater
// For his, we use another output channle as the channel (default==0) we are
// For his, we use another output channel as the channel (default==0) we are
// receiving the messages on.
#define REPEATER 0

Expand All @@ -128,7 +133,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
Expand All @@ -147,15 +152,15 @@
// functions to set/reset certain parameters from remote.
#define GATEWAYMGT 0

// Do extensive loggin
// Do extensive logging
// Use the ESP8266 SPIFS filesystem to do extensive logging.
// We must take care that the filesystem never(!) is full, and for that purpose we
// rather have new records/line of statistics than very old.
// Of course we must store enough records to make the filesystem work
//
#define STAT_LOG 1

// Name of he configfile in SPIFFs filesystem
// Name of the configfile in SPIFFs filesystem
// In this file we store the configuration and other relevant info that should
// survive a reboot of the gateway
#define CONFIGFILE "/gwayConfig.txt"
Expand Down
30 changes: 15 additions & 15 deletions ESP-sc-gway/ESP-sc-gway.ino
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ uint16_t frameCount=0; // We write this to SPIFF file
int mutexSPI = 1;

// ----------------------------------------------------------------------------
// FORWARD DECARATIONS
// FORWARD DECLARATIONS
// These forward declarations are done since other .ino fils are linked by the
// compiler/linker AFTER the main ESP-sc-gway.ino file.
// And espcesially when calling functions with ICACHE_RAM_ATTR the complier
// And especially when calling functions with ICACHE_RAM_ATTR the complier
// does not want this.
// Solution can also be to pecify less STRICT compile options in Makefile
// Solution can also be to specify less STRICT compile options in Makefile
// ----------------------------------------------------------------------------

void ICACHE_RAM_ATTR Interrupt_0();
Expand Down Expand Up @@ -689,7 +689,7 @@ int readUdp(int packetSize)

if (WlanConnect(10) < 0) {
#if DUSB>=1
Serial.print(F("readdUdp: ERROR connecting to WLAN"));
Serial.print(F("readUdp: ERROR connecting to WLAN"));
if (debug>=2) Serial.flush();
#endif
Udp.flush();
Expand All @@ -701,7 +701,7 @@ int readUdp(int packetSize)

if (packetSize > RX_BUFF_SIZE) {
#if DUSB>=1
Serial.print(F("readUDP:: ERROR package of size: "));
Serial.print(F("readUdp:: ERROR package of size: "));
Serial.println(packetSize);
#endif
Udp.flush();
Expand All @@ -712,7 +712,7 @@ int readUdp(int packetSize)
// In practice however this can be any sender!
if (Udp.read(buff_down, packetSize) < packetSize) {
#if DUSB>=1
Serial.println(F("readUsb:: Reading less chars"));
Serial.println(F("readUdp:: Reading less chars"));
return(-1);
#endif
}
Expand Down Expand Up @@ -765,7 +765,7 @@ int readUdp(int packetSize)
#endif
break;

// This message is sent by the server to acknoledge receipt of a
// This message is sent by the server to acknowledge receipt of a
// (sensor) message sent with the code above.
case PKT_PUSH_ACK: // 0x01 DOWN
#if DUSB>=1
Expand All @@ -791,7 +791,7 @@ int readUdp(int packetSize)
break;

// This message type is used to confirm OTAA message to the node
// XXX This message format may also be used for other downstream communucation
// XXX This message format may also be used for other downstream communication
case PKT_PULL_RESP: // 0x03 DOWN
#if DUSB>=1
if (debug>=0) {
Expand Down Expand Up @@ -1280,7 +1280,7 @@ void setup() {
Serial.print(sf);
Serial.print(" on ");
Serial.print((double)freq/1000000);
Serial.println(" Mhz.");
Serial.println(" MHz.");

if (!WiFi.hostByName(NTP_TIMESERVER, ntpServer)) // Get IP address of Timeserver
{
Expand All @@ -1302,7 +1302,7 @@ void setup() {
delay(100);
#endif

// The Over the AIr updates are supported when we have a WiFi connection.
// The Over the Air updates are supported when we have a WiFi connection.
// The NTP time setting does not have to be precise for this function to work.
#if A_OTA==1
setupOta(hostname); // Uses wwwServer
Expand All @@ -1314,7 +1314,7 @@ void setup() {
setupTime(); // Set NTP time host and interval
#else
// If not using the standard libraries, do a manual setting
// of the time. This meyhod works more reliable than the
// of the time. This method works more reliable than the
// interrupt driven method.

//setTime((time_t)getNtpTime());
Expand All @@ -1341,7 +1341,7 @@ void setup() {

delay(100); // Wait after setup

// Setup ad initialise LoRa state machine of _loramModem.ino
// Setup and initialise LoRa state machine of _loramModem.ino
_state = S_INIT;
initLoraModem();

Expand Down Expand Up @@ -1391,7 +1391,7 @@ void setup() {
// we include yield() statements at important points.
//
// Note: If we spend too much time in user processing functions
// and the backend system cannot do its housekeeping, the watchdog
// and the backend system cannot do its housekeeping, the watchdog
// function will be executed which means effectively that the
// program crashes.
// We use yield() a lot to avoid ANY watch dog activity of the program.
Expand Down Expand Up @@ -1460,7 +1460,7 @@ void loop ()
ArduinoOTA.handle();
#endif

// I event is set, we know that we have a (soft) interrupt.
// If 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.
// XXX 180326
Expand Down Expand Up @@ -1525,7 +1525,7 @@ void loop ()

// If the gateway behaves like a node, we do from time to time
// send a node message to the backend server.
// The Gateway nod emessage has nothing to do with the STAT_INTERVAL
// The Gateway node message has nothing to do with the STAT_INTERVAL
// message but we schedule it in the same frequency.
//
#if GATEWAYNODE==1
Expand Down
4 changes: 2 additions & 2 deletions ESP-sc-gway/_gatewayMgt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@


// ----------------------------------------------------------------------------
// Ths function gateway_mgt is called in the UDP Receive function after
// This function gateway_mgt is called in the UDP Receive function after
// all well-known LoRa Gateway messages are scanned.
//
// As part of this function we will listen for another set of messages
// As part of this function, we will listen for another set of messages
// that is defined in loraModem.h.
// All opCodes start with 0x1y for at leaving opcodes 0x00 to 0x0F to the
// pure Gateway protocol
Expand Down
6 changes: 3 additions & 3 deletions ESP-sc-gway/_loraFiles.ino
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ int writeGwayCfg(const char *fn) {
}

// ----------------------------------------------------------------------------
// Write the configuration ad found in the espGwayConfig structure
// Write the configuration as found in the espGwayConfig structure
// to SPIFFS
// ----------------------------------------------------------------------------
int writeConfig(const char *fn, struct espGwayConfig *c) {
Expand Down Expand Up @@ -245,8 +245,8 @@ void addLog(const unsigned char * line, int cnt)
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.logFileRec = 0; // In new logFile start with record 0
gwayConfig.logFileNo++; // Increase file ID
gwayConfig.logFileNum++; // Increase number of log files
}
gwayConfig.logFileRec++;
Expand Down
22 changes: 11 additions & 11 deletions ESP-sc-gway/_loraModem.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
//
//
// SPI AND INTERRUPTS
// The RFM96/SX1276 communicaties with the ESP8266 by means of interrupts
// The RFM96/SX1276 communicates with the ESP8266 by means of interrupts
// and SPI interface. The SPI interface is bidirectional and allows both
// parties to simultaneous write and read to registers.
// Major drawback is that access is not protected for interrupt and non-
// interrupt access. This means that when a program in loop() and a program
// in interrupt do access the readregister and writeRegister() function
// at teh same time that probably an error will occur.
// Therefore it is best to Either not use interrupts AT all (like LMIC)
// or only use these functions in inteerupts and to further processing
// at the same time that probably an error will occur.
// Therefore it is best to either not use interrupts AT all (like LMIC)
// or only use these functions in interrupts and to further processing
// in the main loop() program.
//
// ============================================================================


// ----------------------------------------------------------------------------
// Mutex definitiona
// Mutex definitions
//
// ----------------------------------------------------------------------------
#if MUTEX==1
Expand Down Expand Up @@ -232,7 +232,7 @@ void setRate(uint8_t sf, uint8_t crc)
// ----------------------------------------------------------------------------
// Set the frequency for our gateway
// The function has no parameter other than the freq setting used in init.
// Since we are usin a 1ch gateway this value is set fixed.
// Since we are using a 1ch gateway this value is set fixed.
// ----------------------------------------------------------------------------

void setFreq(uint32_t freq)
Expand Down Expand Up @@ -601,7 +601,7 @@ void txLoraModem(uint8_t *payLoad, uint8_t payLength, uint32_t tmst, uint8_t sfT
// 3. Init spreading factor and other Modem setting
setRate(sfTx, crc);

// Frquency hopping
// Frequency hopping
//writeRegister(REG_HOP_PERIOD, (uint8_t) 0x00); // set 0x24 to 0x00 only for receivers

// 4. Init Frequency, config channel
Expand All @@ -613,7 +613,7 @@ void txLoraModem(uint8_t *payLoad, uint8_t payLength, uint32_t tmst, uint8_t sfT
// 7. prevent node to node communication
writeRegister(REG_INVERTIQ, (uint8_t) iiq); // 0x33, (0x27 or 0x40)

// 8. set the IRQ mapping DIO0=TxDone DIO1=NOP DIO2=NOP (or lesss for 1ch gateway)
// 8. set the IRQ mapping DIO0=TxDone DIO1=NOP DIO2=NOP (or less for 1ch gateway)
writeRegister(REG_DIO_MAPPING_1, (uint8_t)(
MAP_DIO0_LORA_TXDONE |
MAP_DIO1_LORA_NOP |
Expand Down Expand Up @@ -659,7 +659,7 @@ void txLoraModem(uint8_t *payLoad, uint8_t payLength, uint32_t tmst, uint8_t sfT
// - Determine the correct transceiver type (sx1272/RFM92 or sx1276/RFM95)
// - Set the frequency to listen to (1-channel remember)
// - Set Spreading Factor (standard SF7)
// The reset RST pin might not be necessary for at least the RGM95 transceiver
// The reset RST pin might not be necessary for at least the RFM95 transceiver
//
// 1. Put the radio in LoRa mode
// 2. Put modem in sleep or in standby
Expand Down Expand Up @@ -735,7 +735,7 @@ void rxLoraModem()
opmode(OPMODE_RX_SINGLE); // 0x80 | 0x06 (listen one message)
}
else {
// Set Continous Receive Mode, usefull if we stay on one SF
// Set Continous Receive Mode, useful if we stay on one SF
_state= S_RX;
opmode(OPMODE_RX); // 0x80 | 0x05 (listen)
}
Expand All @@ -759,7 +759,7 @@ void rxLoraModem()
// ----------------------------------------------------------------------------
void cadScanner()
{
// 1. Put system in LoRa mode (which destroys all other nodes(
// 1. Put system in LoRa mode (which destroys all other nodes
//opmode(OPMODE_LORA);

// 2. Put the radio in sleep mode
Expand Down
2 changes: 1 addition & 1 deletion ESP-sc-gway/_otaServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void setupOta(char *hostname) {
Serial.println(WiFi.localIP());

// Only if the Webserver is active also
#if A_SERVER==2 // Displaed for the moment
#if A_SERVER==2 // Displayed for the moment
ESPhttpUpdate.rebootOnUpdate(false);

server.on("/esp", HTTP_POST, [&](){
Expand Down
4 changes: 2 additions & 2 deletions ESP-sc-gway/_repeater.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
#define _OCHAN 1

#ifdef _TTNSERVER
#error "Please undefined _THINGSERVER, for REAPETR shutdown WiFi"
#error "Please undefined _THINGSERVER, for REPEATER shutdown WiFi"
#endif

// Send a LoRa message out from the gateway transmitter
// XXX Maybe we should block the received ontul the message is transmitter

int sendLora(char *msg, int len) {
// Check whete len is not exceeding maximum length
// Check when len is not exceeding maximum length
Serial.print("sendLora:: ");

for (int i=0; i< len; i++) {
Expand Down
12 changes: 6 additions & 6 deletions ESP-sc-gway/_stateMachine.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
// - Goto either SCAN or RX
//
// This interrupt routine has been kept as simple and short as possible.
// If we receive an interrupt that does not below to a _state then print error.
// If we receive an interrupt that does not belong to a _state then print error.
// _event is a special variable which indicate that an interrupt event has happened
// and we need to take action OR that we generate a soft interrupt for state machine.
// and we need to take action OR that we generate a soft interrupt for state machine.
//
// NOTE: We may clear the interrupt but leave the flag for the moment.
// The eventHandler should take care of repairing flags between interrupts.
Expand Down Expand Up @@ -211,7 +211,7 @@ void stateMachine()
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
_event = 0; // Make 0, as soon as we have an interrupt
writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF ); // reset all interrupt flags

#if DUSB>=1
Expand Down Expand Up @@ -680,7 +680,7 @@ void stateMachine()


// --------------------------------------------------------------
// Start te transmission of a message in state S-TX
// Start the transmission of a message in state S-TX
// We use S-TXDONE as the state to read the message.
// This is not an interrupt state, we use this state to start transmission
// the interrupt TX-DONE tells us that the transmission was successful.
Expand All @@ -698,7 +698,7 @@ void stateMachine()
#endif
}

// Sset state to transmit
// Set state to transmit
_state = S_TXDONE;
writeRegister(REG_IRQ_FLAGS_MASK, (uint8_t) 0x00);
writeRegister(REG_IRQ_FLAGS, (uint8_t) 0xFF); // reset interrupt flags
Expand Down Expand Up @@ -728,7 +728,7 @@ void stateMachine()


// ---------------------------------------------------
// AFter the transmission is completed by the hardware,
// After the transmission is completed by the hardware,
// the interrupt TXDONE is raised telling us that the tranmission
// was successful.
// If we receive an interrupt on dio0 _state==S_TX it is a TxDone interrupt
Expand Down
Loading