Compare commits
No commits in common. "aebef343146153b4bbc8db4539a4e59ad7c2079f" and "cae484fb53bd9515f7a05c27707a58883c32fd61" have entirely different histories.
aebef34314
...
cae484fb53
Binary file not shown.
@ -1,4 +1,4 @@
|
||||
update=04/11/2025 22:34:12
|
||||
update=22/08/2021 10:09:42
|
||||
version=1
|
||||
last_client=kicad
|
||||
[general]
|
||||
@ -34,7 +34,7 @@ LibDir=
|
||||
[schematic_editor]
|
||||
version=1
|
||||
PageLayoutDescrFile=
|
||||
PlotDirectoryName=../
|
||||
PlotDirectoryName=D:/Users/Think/Programmation/Arduino/Git projects/ESP8266_dual_NRF24l01_gateway/schematic/
|
||||
SubpartIdSeparator=0
|
||||
SubpartFirstId=65
|
||||
NetFmtName=
|
||||
|
||||
@ -5,9 +5,9 @@ $Descr A4 11693 8268
|
||||
encoding utf-8
|
||||
Sheet 1 1
|
||||
Title "ESP8266 Dual NRF24L01 Gateway"
|
||||
Date "2025-11-04"
|
||||
Rev "1.3"
|
||||
Comp "www.web-directories.hd.free.fr"
|
||||
Date "2020-12-29"
|
||||
Rev "1.1"
|
||||
Comp "www.web-directories.tk"
|
||||
Comment1 ""
|
||||
Comment2 ""
|
||||
Comment3 ""
|
||||
@ -562,34 +562,34 @@ $EndComp
|
||||
$Comp
|
||||
L Device:R R10
|
||||
U 1 1 5FF530EA
|
||||
P 4150 5950
|
||||
F 0 "R10" V 4050 5900 50 0000 C CNN
|
||||
F 1 "390" V 4150 5950 50 0000 C CNN
|
||||
F 2 "" V 4080 5950 50 0001 C CNN
|
||||
F 3 "~" H 4150 5950 50 0001 C CNN
|
||||
1 4150 5950
|
||||
P 9450 4550
|
||||
F 0 "R10" V 9350 4500 50 0000 C CNN
|
||||
F 1 "390" V 9450 4550 50 0000 C CNN
|
||||
F 2 "" V 9380 4550 50 0001 C CNN
|
||||
F 3 "~" H 9450 4550 50 0001 C CNN
|
||||
1 9450 4550
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R11
|
||||
U 1 1 5FF53E00
|
||||
P 4150 6150
|
||||
F 0 "R11" V 4050 6100 50 0000 C CNN
|
||||
F 1 "390" V 4150 6150 50 0000 C CNN
|
||||
F 2 "" V 4080 6150 50 0001 C CNN
|
||||
F 3 "~" H 4150 6150 50 0001 C CNN
|
||||
1 4150 6150
|
||||
P 9450 4750
|
||||
F 0 "R11" V 9350 4700 50 0000 C CNN
|
||||
F 1 "390" V 9450 4750 50 0000 C CNN
|
||||
F 2 "" V 9380 4750 50 0001 C CNN
|
||||
F 3 "~" H 9450 4750 50 0001 C CNN
|
||||
1 9450 4750
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L Device:R R14
|
||||
U 1 1 5FF540AA
|
||||
P 4150 6350
|
||||
F 0 "R14" V 4050 6300 50 0000 C CNN
|
||||
F 1 "390" V 4150 6350 50 0000 C CNN
|
||||
F 2 "" V 4080 6350 50 0001 C CNN
|
||||
F 3 "~" H 4150 6350 50 0001 C CNN
|
||||
1 4150 6350
|
||||
P 9450 4950
|
||||
F 0 "R14" V 9350 4900 50 0000 C CNN
|
||||
F 1 "390" V 9450 4950 50 0000 C CNN
|
||||
F 2 "" V 9380 4950 50 0001 C CNN
|
||||
F 3 "~" H 9450 4950 50 0001 C CNN
|
||||
1 9450 4950
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
@ -703,42 +703,44 @@ Wire Wire Line
|
||||
Wire Wire Line
|
||||
6700 3400 7600 3400
|
||||
Wire Wire Line
|
||||
8100 2100 9150 2100
|
||||
8900 3400 8900 2100
|
||||
Wire Wire Line
|
||||
8900 2100 9150 2100
|
||||
$Comp
|
||||
L Device:LED_RGBA D1
|
||||
U 1 1 607ADA27
|
||||
P 4500 6150
|
||||
F 0 "D1" H 4500 6647 50 0000 C CNN
|
||||
F 1 "LED_RGBA" H 4500 6556 50 0000 C CNN
|
||||
F 2 "" H 4500 6100 50 0001 C CNN
|
||||
F 3 "~" H 4500 6100 50 0001 C CNN
|
||||
1 4500 6150
|
||||
P 9800 4750
|
||||
F 0 "D1" H 9800 5247 50 0000 C CNN
|
||||
F 1 "LED_RGBA" H 9800 5156 50 0000 C CNN
|
||||
F 2 "" H 9800 4700 50 0001 C CNN
|
||||
F 3 "~" H 9800 4700 50 0001 C CNN
|
||||
1 9800 4750
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:+3.3V #PWR0117
|
||||
U 1 1 607C47BE
|
||||
P 4900 6150
|
||||
F 0 "#PWR0117" H 4900 6000 50 0001 C CNN
|
||||
F 1 "+3.3V" H 4915 6323 50 0000 C CNN
|
||||
F 2 "" H 4900 6150 50 0001 C CNN
|
||||
F 3 "" H 4900 6150 50 0001 C CNN
|
||||
1 4900 6150
|
||||
P 10200 4750
|
||||
F 0 "#PWR0117" H 10200 4600 50 0001 C CNN
|
||||
F 1 "+3.3V" H 10215 4923 50 0000 C CNN
|
||||
F 2 "" H 10200 4750 50 0001 C CNN
|
||||
F 3 "" H 10200 4750 50 0001 C CNN
|
||||
1 10200 4750
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
4700 6150 4900 6150
|
||||
10000 4750 10200 4750
|
||||
Text GLabel 6700 3500 2 50 Input ~ 0
|
||||
P_2
|
||||
Text GLabel 6700 3600 2 50 Input ~ 0
|
||||
P_3
|
||||
Text GLabel 6700 3700 2 50 Input ~ 0
|
||||
P_4
|
||||
Text GLabel 4000 5950 0 50 Input ~ 0
|
||||
Text GLabel 9300 4550 0 50 Input ~ 0
|
||||
P_2
|
||||
Text GLabel 4000 6150 0 50 Input ~ 0
|
||||
Text GLabel 9300 4750 0 50 Input ~ 0
|
||||
P_3
|
||||
Text GLabel 4000 6350 0 50 Input ~ 0
|
||||
Text GLabel 9300 4950 0 50 Input ~ 0
|
||||
P_4
|
||||
$Comp
|
||||
L Device:R R5
|
||||
@ -816,6 +818,9 @@ Text GLabel 5300 4100 0 50 Input ~ 0
|
||||
ESP_GPIO_3_RXD
|
||||
Wire Wire Line
|
||||
5300 4100 5400 4100
|
||||
NoConn ~ 6700 4000
|
||||
NoConn ~ 6700 3900
|
||||
NoConn ~ 6700 3800
|
||||
NoConn ~ 1800 1600
|
||||
NoConn ~ 1800 1700
|
||||
NoConn ~ 1800 1800
|
||||
@ -838,6 +843,8 @@ F 3 "~" H 7750 3400 50 0001 C CNN
|
||||
1 7750 3400
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
7900 3400 8900 3400
|
||||
$Comp
|
||||
L Device:R R15
|
||||
U 1 1 60CE8759
|
||||
@ -864,144 +871,4 @@ F 3 "~" H 1550 6100 50 0001 C CNN
|
||||
1 1550 6100
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
$Comp
|
||||
L RF_Module:RFM95W-868S2 U6
|
||||
U 1 1 690A94A6
|
||||
P 9700 4350
|
||||
F 0 "U6" H 9000 4900 50 0000 C CNN
|
||||
F 1 "RFM95W-868S2" H 9250 4800 50 0000 C CNN
|
||||
F 2 "" H 6400 6000 50 0001 C CNN
|
||||
F 3 "https://www.hoperf.com/data/upload/portal/20181127/5bfcbea20e9ef.pdf" H 6400 6000 50 0001 C CNN
|
||||
1 9700 4350
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
7900 3400 8100 3400
|
||||
Wire Wire Line
|
||||
8100 3400 8100 2100
|
||||
$Comp
|
||||
L Device:Antenna AE1
|
||||
U 1 1 690CE3E1
|
||||
P 10200 3850
|
||||
F 0 "AE1" H 10280 3839 50 0000 L CNN
|
||||
F 1 "Antenna" H 10280 3748 50 0000 L CNN
|
||||
F 2 "" H 10200 3850 50 0001 C CNN
|
||||
F 3 "~" H 10200 3850 50 0001 C CNN
|
||||
1 10200 3850
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$Comp
|
||||
L power:+3.3V #PWR01
|
||||
U 1 1 690D17C6
|
||||
P 9700 3350
|
||||
F 0 "#PWR01" H 9700 3200 50 0001 C CNN
|
||||
F 1 "+3.3V" H 9715 3523 50 0000 C CNN
|
||||
F 2 "" H 9700 3350 50 0001 C CNN
|
||||
F 3 "" H 9700 3350 50 0001 C CNN
|
||||
1 9700 3350
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
9700 3350 9700 3500
|
||||
NoConn ~ 10200 4250
|
||||
NoConn ~ 10200 4350
|
||||
NoConn ~ 10200 4550
|
||||
NoConn ~ 10200 4650
|
||||
NoConn ~ 10200 4450
|
||||
$Comp
|
||||
L power:GND #PWR03
|
||||
U 1 1 690F101C
|
||||
P 9700 5100
|
||||
F 0 "#PWR03" H 9700 4850 50 0001 C CNN
|
||||
F 1 "GND" H 9705 4927 50 0000 C CNN
|
||||
F 2 "" H 9700 5100 50 0001 C CNN
|
||||
F 3 "" H 9700 5100 50 0001 C CNN
|
||||
1 9700 5100
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
9600 4950 9600 5000
|
||||
Wire Wire Line
|
||||
9600 5000 9700 5000
|
||||
Wire Wire Line
|
||||
9700 5000 9700 5100
|
||||
Wire Wire Line
|
||||
9800 4950 9800 5000
|
||||
Wire Wire Line
|
||||
9800 5000 9700 5000
|
||||
Connection ~ 9700 5000
|
||||
Wire Wire Line
|
||||
9700 5000 9700 4950
|
||||
$Comp
|
||||
L Device:C C7
|
||||
U 1 1 690FB7DA
|
||||
P 9550 3500
|
||||
F 0 "C7" H 9665 3546 50 0000 L CNN
|
||||
F 1 "1µF" H 9665 3455 50 0000 L CNN
|
||||
F 2 "" H 9588 3350 50 0001 C CNN
|
||||
F 3 "~" H 9550 3500 50 0001 C CNN
|
||||
1 9550 3500
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
Connection ~ 9700 3500
|
||||
Wire Wire Line
|
||||
9700 3500 9700 3850
|
||||
$Comp
|
||||
L power:GND #PWR02
|
||||
U 1 1 69100320
|
||||
P 9350 3550
|
||||
F 0 "#PWR02" H 9350 3300 50 0001 C CNN
|
||||
F 1 "GND" H 9355 3377 50 0000 C CNN
|
||||
F 2 "" H 9350 3550 50 0001 C CNN
|
||||
F 3 "" H 9350 3550 50 0001 C CNN
|
||||
1 9350 3550
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
9400 3500 9350 3500
|
||||
Wire Wire Line
|
||||
9350 3500 9350 3550
|
||||
Text GLabel 8950 4050 0 50 Input ~ 0
|
||||
ESP_GPIO_14_CLK
|
||||
Wire Wire Line
|
||||
8950 4050 9200 4050
|
||||
Text GLabel 8950 4150 0 50 Input ~ 0
|
||||
ESP_GPIO_13_MOSI
|
||||
Wire Wire Line
|
||||
8950 4150 9200 4150
|
||||
Text GLabel 8950 4250 0 50 Input ~ 0
|
||||
ESP_GPIO_12_MISO
|
||||
Wire Wire Line
|
||||
8950 4250 9200 4250
|
||||
Text GLabel 6700 3800 2 50 Input ~ 0
|
||||
P_5
|
||||
Text GLabel 6700 3900 2 50 Input ~ 0
|
||||
P_6
|
||||
Text GLabel 6700 4000 2 50 Input ~ 0
|
||||
P_7
|
||||
Text GLabel 8950 4350 0 50 Input ~ 0
|
||||
P_5
|
||||
Wire Wire Line
|
||||
8950 4350 9200 4350
|
||||
Text GLabel 8950 4550 0 50 Input ~ 0
|
||||
P_6
|
||||
Wire Wire Line
|
||||
8950 4550 9200 4550
|
||||
Text GLabel 10850 4750 2 50 Input ~ 0
|
||||
P_7
|
||||
Wire Wire Line
|
||||
10200 4750 10350 4750
|
||||
$Comp
|
||||
L Device:R R18
|
||||
U 1 1 6911AF16
|
||||
P 10500 4750
|
||||
F 0 "R18" V 10600 4750 50 0000 C CNN
|
||||
F 1 "6.8k" V 10500 4750 50 0000 C CNN
|
||||
F 2 "" V 10430 4750 50 0001 C CNN
|
||||
F 3 "~" H 10500 4750 50 0001 C CNN
|
||||
1 10500 4750
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
10650 4750 10850 4750
|
||||
$EndSCHEMATC
|
||||
|
||||
211
src/app/app.ino
211
src/app/app.ino
@ -1,8 +1,7 @@
|
||||
/**
|
||||
* Author : Anatole SCHRAMM-HENRY
|
||||
* Created the : 11/07/2021
|
||||
* Last updated : 04/11/2025
|
||||
* This is a quick and dirty gateway firmware to receive and save data from sensors to a database
|
||||
* This is a quick and dirty firmewire to receive and save the data in the database
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -10,45 +9,23 @@
|
||||
#include <PCF8574.h>
|
||||
#include <HttpClient.h>
|
||||
#include "RF24.h"
|
||||
#include <LoRa.h>
|
||||
#include "definition.h"
|
||||
#include "credentials.h"
|
||||
|
||||
/* NRF pinout definition and settings */
|
||||
#define NRF_1_CE (15) //chip enable
|
||||
#define NRF_1_CS (5) //chip select
|
||||
#define NRF_1_IRQ (PCF8574::P1)
|
||||
|
||||
#define NRF_2_CE (16) //chip enable
|
||||
#define NRF_2_CS (4) //chip select
|
||||
#define NRF_2_IRQ (PCF8574::P0)
|
||||
#define NRF_1_CE 15 //chip enable
|
||||
#define NRF_2_CE 16 //chip enable
|
||||
|
||||
#define NRF_CHANNEL (108) //0-125
|
||||
#define NRF_PA_LEVEL (RF24_PA_MAX)
|
||||
#define NRF_DATA_RATE (RF24_250KBPS) //250 Kb/s, 1 Mb/s & 2 Mb/s
|
||||
#define NRF_1_CS 5 //chip select
|
||||
#define NRF_2_CS 4 //chip select
|
||||
|
||||
#define RECV_CHECK 5000 //We test every 5s if we received something that did not trigger an IRQ (missed)
|
||||
#define WIFI_CHECK_TIMEOUT 20000 //We check every 20 seconds the WiFi state
|
||||
#define PREVENTIVE_RESET_DELAY 18000000 //Every 5 hours the MCU is reseted, this SHOULD NOT be necessary
|
||||
|
||||
/* RGB LED pinout */
|
||||
#define LED_RED_PIN (PCF8574::P2)
|
||||
#define LED_GREEN_PIN (PCF8574::P3)
|
||||
#define LED_BLUE_PIN (PCF8574::P4)
|
||||
|
||||
/* LoRa module pinout definition (using the IO expander) */
|
||||
#define LORA_CS_PIN (PCF8574::P5)
|
||||
#define LORA_RST_PIN (PCF8574::P6)
|
||||
#define LORA_DI0_PIN (PCF8574::P7)
|
||||
|
||||
#define LORA_BAND (868E6)
|
||||
#define LORA_SPREADING_FACTOR (10) //6-12
|
||||
|
||||
/* PCF8574 IO expander pinout */
|
||||
#define PCF_INT_PIN (D9)
|
||||
#define CHAN 108 //0-125
|
||||
#define RECV_CHECK 5000 //We test every 5s if we received something
|
||||
#define WIFI_CHECK_TIMEOUT 20000
|
||||
#define PREVENTIVE_RESET_DELAY 18000000 //Every 5 hours
|
||||
|
||||
uint8_t payload[32] = {0};
|
||||
DataPacket packetHeader;
|
||||
DataPacket dp;
|
||||
WeatherStationDataPacket wsdp;
|
||||
MailboxDataPacket mdp;
|
||||
|
||||
@ -67,56 +44,25 @@ uint32_t timeStamp(0), irqSaver(0), resetTimeStamp(0);
|
||||
uint32_t freeMem(0);
|
||||
uint16_t biggestContigMemBlock(0);
|
||||
uint8_t frag(0);
|
||||
HttpClient::HttpQueryStatus insertIntoDBError(HttpClient::HttpQueryStatus::SUCCESS);
|
||||
int insertIntoDBError(0);
|
||||
volatile boolean IRQFlag(false);
|
||||
volatile boolean IRQIsLoRa(false);
|
||||
boolean waitingForResetSignal(false), resetNow(false);
|
||||
|
||||
void PCFPinMode(uint8_t pin, uint8_t mode)
|
||||
IRAM_ATTR void NRFIRQsHandler(void *p)
|
||||
{
|
||||
PCF.pinMode(static_cast<PCF8574::Pin>(pin), static_cast<boolean>(mode));
|
||||
}
|
||||
|
||||
void PCFDigitalWrite(uint8_t pin, uint8_t val)
|
||||
{
|
||||
PCF.digitalWrite(static_cast<PCF8574::Pin>(pin), static_cast<boolean>(val));
|
||||
}
|
||||
|
||||
void onLoRaReceive(int payload_size)
|
||||
{
|
||||
IRQIsLoRa = true;
|
||||
PCF.digitalWrite(LED_RED_PIN, LOW);
|
||||
|
||||
int read_size = LoRa.read(payload, sizeof(payload));
|
||||
|
||||
Serial.printf("Read LoRa payload size of : %d\n", read_size);
|
||||
if (read_size != payload_size)
|
||||
Serial.printf("/!\\Read size(%d) != payload size(%d)\n", read_size, payload_size);
|
||||
Serial.printf("Packet RSSI : %d dBm\n", LoRa.packetRssi());
|
||||
|
||||
PCF.digitalWrite(LED_RED_PIN, HIGH);
|
||||
}
|
||||
|
||||
IRAM_ATTR void PCFIRQHandler(void *p)
|
||||
{
|
||||
Serial.println("PCF IRQs detected !");
|
||||
bool pinStates[8];
|
||||
PCF.digitalReadAll(pinStates);
|
||||
Serial.println("NRF IRQs detected !");
|
||||
*(boolean *)p = true;
|
||||
|
||||
/* If the IRQ pin is the DIO1, manually call the LoRa IRQ handler */
|
||||
if(pinStates[7] == HIGH)
|
||||
{
|
||||
LoRa.handleDio0Rise();
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
//We do not need to read on the serial bus
|
||||
Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
|
||||
delay(1000);
|
||||
Serial.println("\nSetup begin");
|
||||
//We set the RXD0 as a GPIO
|
||||
pinMode(D9, FUNCTION_3);
|
||||
pinMode(D9, INPUT_PULLUP);
|
||||
attachInterruptArg(D9,&(NRFIRQsHandler), (void *)&IRQFlag, FALLING);
|
||||
//We set the WiFi part up :
|
||||
gotIp = WiFi.onStationModeGotIP(&(gotIpFunc));
|
||||
lostConnection = WiFi.onStationModeDisconnected(&(lostConnectionFunc));
|
||||
@ -126,7 +72,6 @@ void setup()
|
||||
WiFi.softAPdisconnect(true);
|
||||
Serial.println("Connecting to the access point");
|
||||
WiFi.begin(SSID, PWD);
|
||||
|
||||
//We initialize the dictionary
|
||||
//These keys are used to post data for the weather station :
|
||||
weatherStationPostData.add("accessCode", DictionaryHelper::StringEntity(ACCESS_CODE));
|
||||
@ -139,8 +84,7 @@ void setup()
|
||||
weatherStationPostData.add("humidity", DictionaryHelper::StringEntity(NULL));
|
||||
weatherStationPostData.add("compensated_humidity", DictionaryHelper::StringEntity(NULL));
|
||||
weatherStationPostData.add("htu_tmp", DictionaryHelper::StringEntity(NULL));
|
||||
|
||||
//These keys are used to post data for the mailbox :
|
||||
//These keys are used to post data for the mailbox
|
||||
mailboxPostData.add("accessCode", DictionaryHelper::StringEntity(ACCESS_CODE));
|
||||
mailboxPostData.add("deviceType", DictionaryHelper::StringEntity(MAILBOX_DEV_TYPE));
|
||||
mailboxPostData.add("packetUID", DictionaryHelper::StringEntity(NULL));
|
||||
@ -154,9 +98,9 @@ void setup()
|
||||
else
|
||||
Serial.println("NRF 1 is detected");
|
||||
|
||||
NRF_1.setChannel(NRF_CHANNEL);
|
||||
NRF_1.setPALevel(NRF_PA_LEVEL);
|
||||
NRF_1.setDataRate(NRF_DATA_RATE);
|
||||
NRF_1.setChannel(CHAN);
|
||||
NRF_1.setPALevel(RF24_PA_MIN);
|
||||
NRF_1.setDataRate(RF24_250KBPS);
|
||||
NRF_1.setRetries(8,15);
|
||||
NRF_1.openReadingPipe(1, ADDR);
|
||||
NRF_1.startListening();
|
||||
@ -167,9 +111,9 @@ void setup()
|
||||
else
|
||||
Serial.println("NRF 2 is detected");
|
||||
|
||||
NRF_2.setChannel(NRF_CHANNEL);
|
||||
NRF_2.setPALevel(NRF_PA_LEVEL);
|
||||
NRF_2.setDataRate(NRF_DATA_RATE);
|
||||
NRF_2.setChannel(CHAN);
|
||||
NRF_2.setPALevel(RF24_PA_MIN);
|
||||
NRF_2.setDataRate(RF24_250KBPS);
|
||||
NRF_2.setRetries(8,15);
|
||||
NRF_2.openReadingPipe(1, ADDR);
|
||||
NRF_2.startListening();
|
||||
@ -177,82 +121,20 @@ void setup()
|
||||
//Setting the I2C pins and the PCF8574
|
||||
Wire.begin(0,2);
|
||||
Serial.printf("PCF %s\n", PCF.begin() ? "found" : "not found");
|
||||
PCF.pinMode(LED_RED_PIN, OUTPUT);
|
||||
PCF.pinMode(LED_GREEN_PIN, OUTPUT);
|
||||
PCF.pinMode(LED_BLUE_PIN, OUTPUT);
|
||||
|
||||
/* Configuring LoRa module and RF settings */
|
||||
LoRa.setPins(LORA_CS_PIN, LORA_RST_PIN, LORA_DI0_PIN);
|
||||
/* Setting custom GPIO as the LoRa module signals are driven by the IO Expender */
|
||||
LoRa.setCustomGPIOFn(&(PCFPinMode), &(PCFDigitalWrite));
|
||||
|
||||
Serial.printf("LoRa module %s\n", LoRa.begin(LORA_BAND) ? "found" : "not found");
|
||||
LoRa.setSpreadingFactor(LORA_SPREADING_FACTOR);
|
||||
LoRa.enableCrc();
|
||||
LoRa.onReceive(&(onLoRaReceive));
|
||||
// Let's start listening to LoRa packets
|
||||
LoRa.receive();
|
||||
|
||||
//We set the esp8266's RXD0 as a GPIO
|
||||
pinMode(PCF_INT_PIN, INPUT_PULLUP);
|
||||
attachInterruptArg(PCF_INT_PIN, &(PCFIRQHandler), (void *)&IRQFlag, ONLOW);
|
||||
PCF.pinMode(PCF8574::P2, OUTPUT);
|
||||
PCF.pinMode(PCF8574::P3, OUTPUT);
|
||||
PCF.pinMode(PCF8574::P4, OUTPUT);
|
||||
Serial.println("End setup");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
//We check if we got and IRQ from one, both NRFs or the LoRa module
|
||||
//We check if we got and IRQ from one, both NRFs
|
||||
if(IRQFlag || (millis() - irqSaver > RECV_CHECK))
|
||||
{
|
||||
if(!IRQIsLoRa && PCF.digitalRead(LORA_DI0_PIN))
|
||||
{
|
||||
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IRQ MISSED FOR LoRa MODULE");
|
||||
if(LoRa.parsePacket() > 0)
|
||||
{
|
||||
LoRa.read(payload, sizeof(payload));
|
||||
//Set IRQ to true to handle LoRa received payload
|
||||
IRQIsLoRa = true;
|
||||
}
|
||||
LoRa.receive();
|
||||
}
|
||||
|
||||
if(IRQIsLoRa)
|
||||
{
|
||||
//Payload already retrieved in LoRa module IRQ or in the previous code part
|
||||
memcpy(&packetHeader, payload, sizeof(packetHeader));
|
||||
switch(packetHeader.header)
|
||||
{
|
||||
case WEATHER_STATION:
|
||||
{
|
||||
memcpy(&wsdp, payload, sizeof(wsdp));
|
||||
debugStruct(&wsdp);
|
||||
insertIntoDBError = insertIntoDB(&wsdp);
|
||||
}
|
||||
break;
|
||||
case CONNECTED_MAILBOX:
|
||||
{
|
||||
memcpy(&mdp, payload, sizeof(mdp));
|
||||
debugStruct(&mdp);
|
||||
insertIntoDBError = insertIntoDB(&mdp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(waitingForResetSignal)resetNow = true;
|
||||
|
||||
IRQIsLoRa = false;
|
||||
}
|
||||
|
||||
if(PCF.digitalRead(LORA_DI0_PIN))
|
||||
{
|
||||
Serial.println("LoRa module DI0 stuck high !");
|
||||
}
|
||||
|
||||
bool tx_ok, tx_fail, rx_ready;
|
||||
//We read the PCFs IO to check which NRF raised the IRQ :
|
||||
if(!PCF.digitalRead(NRF_1_IRQ)) //IRQs are active low
|
||||
if(!PCF.digitalRead(PCF8574::P1)) //IRQs are active low
|
||||
{
|
||||
if(!IRQFlag)
|
||||
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IRQ MISSED FOR NRF 1");
|
||||
@ -271,9 +153,9 @@ void loop()
|
||||
Serial.printf("NRF 1 Received %u bytes with sig(%s) : \n",NRF_1.getPayloadSize(), NRF_1.testRPD()?"good":"bad");
|
||||
NRF_1.read(payload, sizeof(payload));
|
||||
|
||||
memcpy(&packetHeader, payload, sizeof(packetHeader));
|
||||
memcpy(&dp, payload, sizeof(dp));
|
||||
|
||||
switch(packetHeader.header)
|
||||
switch(dp.header)
|
||||
{
|
||||
case WEATHER_STATION:
|
||||
{
|
||||
@ -297,7 +179,7 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
if(!PCF.digitalRead(NRF_2_IRQ)) //IRQs are active low
|
||||
if(!PCF.digitalRead(PCF8574::P0)) //IRQs are active low
|
||||
{
|
||||
if(!IRQFlag)
|
||||
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IRQ MISSED FOR NRF 2");
|
||||
@ -316,9 +198,9 @@ void loop()
|
||||
Serial.printf("NRF 2 Received %u bytes with sig(%s) : \n",NRF_2.getPayloadSize(), NRF_2.testRPD()?"good":"bad");
|
||||
NRF_2.read(payload, sizeof(payload));
|
||||
|
||||
memcpy(&packetHeader, payload, sizeof(packetHeader));
|
||||
memcpy(&dp, payload, sizeof(dp));
|
||||
|
||||
switch(packetHeader.header)
|
||||
switch(dp.header)
|
||||
{
|
||||
case WEATHER_STATION:
|
||||
{
|
||||
@ -362,12 +244,11 @@ void loop()
|
||||
//Here we check if we are still connected
|
||||
if(millis() - timeStamp > WIFI_CHECK_TIMEOUT)
|
||||
{
|
||||
//PCF.togglePin(PCF8574::P2);
|
||||
//PCF.togglePin(PCF8574::P3);
|
||||
//PCF.togglePin(PCF8574::P4);
|
||||
ESP.getHeapStats(&freeMem, &biggestContigMemBlock, &frag);
|
||||
printf("Memory Info :\n - Free Mem > %u\n - Heap frag > %u\n - Max block > %u\nWiFi RSSI : %d\n",
|
||||
freeMem, frag,
|
||||
biggestContigMemBlock,
|
||||
WiFi.RSSI());
|
||||
|
||||
printf("Memory Info :\n - Free Mem > %u\n - Heap frag > %u\n - Max block > %u\nSign strength : %d\n", freeMem, frag, biggestContigMemBlock,WiFi.RSSI());
|
||||
Serial.println("Checking wifi link : ");
|
||||
if(WiFi.isConnected())
|
||||
{
|
||||
@ -389,7 +270,7 @@ void loop()
|
||||
resetTimeStamp = millis();
|
||||
}
|
||||
|
||||
if((waitingForResetSignal && resetNow) || insertIntoDBError == HttpClient::HttpQueryStatus::ERR_CONN)
|
||||
if((waitingForResetSignal && resetNow) || insertIntoDBError == -125)
|
||||
{
|
||||
ESP.reset();
|
||||
}
|
||||
@ -410,10 +291,10 @@ void lostConnectionFunc(const WiFiEventStationModeDisconnected &event)
|
||||
Serial.println("Lost connection, will try to reconnect ...");
|
||||
}
|
||||
|
||||
HttpClient::HttpQueryStatus insertIntoDB(WeatherStationDataPacket *p)
|
||||
int insertIntoDB(WeatherStationDataPacket *p)
|
||||
{
|
||||
char buffer[100] = "";
|
||||
HttpClient::HttpQueryStatus result(HttpClient::HttpQueryStatus::SUCCESS);
|
||||
int result(0);
|
||||
//We get the values and put it in our dictionary
|
||||
sprintf(buffer ,"%u", p->id);
|
||||
weatherStationPostData("packetUID")->setString(buffer);
|
||||
@ -439,7 +320,7 @@ HttpClient::HttpQueryStatus insertIntoDB(WeatherStationDataPacket *p)
|
||||
sprintf(buffer, "%f", p->htuTemp);
|
||||
weatherStationPostData("htu_tmp")->setString(buffer);
|
||||
|
||||
if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &weatherStationPostData)) == HttpClient::HttpQueryStatus::SUCCESS)
|
||||
if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &weatherStationPostData)) == 0)
|
||||
{
|
||||
Serial.println("Data posted successfully");
|
||||
HttpClient::HTTP_CODE response = DBHost.isReplyAvailable(2000);
|
||||
@ -489,10 +370,10 @@ void debugStruct(WeatherStationDataPacket *p)
|
||||
Serial.println(" *C");
|
||||
}
|
||||
|
||||
HttpClient::HttpQueryStatus insertIntoDB(MailboxDataPacket *p)
|
||||
int insertIntoDB(MailboxDataPacket *p)
|
||||
{
|
||||
char buffer[100] = "";
|
||||
HttpClient::HttpQueryStatus result(HttpClient::HttpQueryStatus::SUCCESS);
|
||||
int result(0);
|
||||
//We get the values and put it in our dictionary
|
||||
sprintf(buffer ,"%u", p->id);
|
||||
mailboxPostData("packetUID")->setString(buffer);
|
||||
@ -515,7 +396,7 @@ HttpClient::HttpQueryStatus insertIntoDB(MailboxDataPacket *p)
|
||||
break;
|
||||
}
|
||||
|
||||
if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &mailboxPostData)) == HttpClient::HttpQueryStatus::SUCCESS)
|
||||
if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &mailboxPostData)) == 0)
|
||||
{
|
||||
Serial.println("Data posted successfully");
|
||||
HttpClient::HTTP_CODE response = DBHost.isReplyAvailable(5000); //We increase the timeout because sending a mail on the server side takes some time.
|
||||
|
||||
@ -347,22 +347,6 @@ int LoRaClass::read()
|
||||
return readRegister(REG_FIFO);
|
||||
}
|
||||
|
||||
int LoRaClass::read(uint8_t *buffer, size_t len)
|
||||
{
|
||||
if(!buffer) return 0;
|
||||
|
||||
size_t nbread = 0;
|
||||
while(nbread < len && available())
|
||||
{
|
||||
int c = read();
|
||||
if(c == -1) break;
|
||||
|
||||
buffer[nbread++] = c;
|
||||
}
|
||||
|
||||
return nbread;
|
||||
}
|
||||
|
||||
int LoRaClass::peek()
|
||||
{
|
||||
if (!available()) {
|
||||
|
||||
@ -54,7 +54,6 @@ public:
|
||||
// from Stream
|
||||
virtual int available();
|
||||
virtual int read();
|
||||
virtual int read(uint8_t *buffer, size_t len);
|
||||
virtual int peek();
|
||||
virtual void flush();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user