Compare commits
5 Commits
202f7e24d6
...
8546142b6c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8546142b6c | ||
|
|
97bdcec0cf | ||
| 19d71b8735 | |||
|
|
628a38d6c2 | ||
|
|
ebc1444ca4 |
Binary file not shown.
@ -1,4 +1,4 @@
|
|||||||
update=22/08/2021 10:09:42
|
update=04/11/2025 22:34:12
|
||||||
version=1
|
version=1
|
||||||
last_client=kicad
|
last_client=kicad
|
||||||
[general]
|
[general]
|
||||||
@ -34,7 +34,7 @@ LibDir=
|
|||||||
[schematic_editor]
|
[schematic_editor]
|
||||||
version=1
|
version=1
|
||||||
PageLayoutDescrFile=
|
PageLayoutDescrFile=
|
||||||
PlotDirectoryName=D:/Users/Think/Programmation/Arduino/Git projects/ESP8266_dual_NRF24l01_gateway/schematic/
|
PlotDirectoryName=../
|
||||||
SubpartIdSeparator=0
|
SubpartIdSeparator=0
|
||||||
SubpartFirstId=65
|
SubpartFirstId=65
|
||||||
NetFmtName=
|
NetFmtName=
|
||||||
|
|||||||
@ -5,9 +5,9 @@ $Descr A4 11693 8268
|
|||||||
encoding utf-8
|
encoding utf-8
|
||||||
Sheet 1 1
|
Sheet 1 1
|
||||||
Title "ESP8266 Dual NRF24L01 Gateway"
|
Title "ESP8266 Dual NRF24L01 Gateway"
|
||||||
Date "2020-12-29"
|
Date "2025-11-04"
|
||||||
Rev "1.1"
|
Rev "1.3"
|
||||||
Comp "www.web-directories.tk"
|
Comp "www.web-directories.hd.free.fr"
|
||||||
Comment1 ""
|
Comment1 ""
|
||||||
Comment2 ""
|
Comment2 ""
|
||||||
Comment3 ""
|
Comment3 ""
|
||||||
@ -562,34 +562,34 @@ $EndComp
|
|||||||
$Comp
|
$Comp
|
||||||
L Device:R R10
|
L Device:R R10
|
||||||
U 1 1 5FF530EA
|
U 1 1 5FF530EA
|
||||||
P 9450 4550
|
P 4150 5950
|
||||||
F 0 "R10" V 9350 4500 50 0000 C CNN
|
F 0 "R10" V 4050 5900 50 0000 C CNN
|
||||||
F 1 "390" V 9450 4550 50 0000 C CNN
|
F 1 "390" V 4150 5950 50 0000 C CNN
|
||||||
F 2 "" V 9380 4550 50 0001 C CNN
|
F 2 "" V 4080 5950 50 0001 C CNN
|
||||||
F 3 "~" H 9450 4550 50 0001 C CNN
|
F 3 "~" H 4150 5950 50 0001 C CNN
|
||||||
1 9450 4550
|
1 4150 5950
|
||||||
0 1 1 0
|
0 1 1 0
|
||||||
$EndComp
|
$EndComp
|
||||||
$Comp
|
$Comp
|
||||||
L Device:R R11
|
L Device:R R11
|
||||||
U 1 1 5FF53E00
|
U 1 1 5FF53E00
|
||||||
P 9450 4750
|
P 4150 6150
|
||||||
F 0 "R11" V 9350 4700 50 0000 C CNN
|
F 0 "R11" V 4050 6100 50 0000 C CNN
|
||||||
F 1 "390" V 9450 4750 50 0000 C CNN
|
F 1 "390" V 4150 6150 50 0000 C CNN
|
||||||
F 2 "" V 9380 4750 50 0001 C CNN
|
F 2 "" V 4080 6150 50 0001 C CNN
|
||||||
F 3 "~" H 9450 4750 50 0001 C CNN
|
F 3 "~" H 4150 6150 50 0001 C CNN
|
||||||
1 9450 4750
|
1 4150 6150
|
||||||
0 1 1 0
|
0 1 1 0
|
||||||
$EndComp
|
$EndComp
|
||||||
$Comp
|
$Comp
|
||||||
L Device:R R14
|
L Device:R R14
|
||||||
U 1 1 5FF540AA
|
U 1 1 5FF540AA
|
||||||
P 9450 4950
|
P 4150 6350
|
||||||
F 0 "R14" V 9350 4900 50 0000 C CNN
|
F 0 "R14" V 4050 6300 50 0000 C CNN
|
||||||
F 1 "390" V 9450 4950 50 0000 C CNN
|
F 1 "390" V 4150 6350 50 0000 C CNN
|
||||||
F 2 "" V 9380 4950 50 0001 C CNN
|
F 2 "" V 4080 6350 50 0001 C CNN
|
||||||
F 3 "~" H 9450 4950 50 0001 C CNN
|
F 3 "~" H 4150 6350 50 0001 C CNN
|
||||||
1 9450 4950
|
1 4150 6350
|
||||||
0 1 1 0
|
0 1 1 0
|
||||||
$EndComp
|
$EndComp
|
||||||
$Comp
|
$Comp
|
||||||
@ -703,44 +703,42 @@ Wire Wire Line
|
|||||||
Wire Wire Line
|
Wire Wire Line
|
||||||
6700 3400 7600 3400
|
6700 3400 7600 3400
|
||||||
Wire Wire Line
|
Wire Wire Line
|
||||||
8900 3400 8900 2100
|
8100 2100 9150 2100
|
||||||
Wire Wire Line
|
|
||||||
8900 2100 9150 2100
|
|
||||||
$Comp
|
$Comp
|
||||||
L Device:LED_RGBA D1
|
L Device:LED_RGBA D1
|
||||||
U 1 1 607ADA27
|
U 1 1 607ADA27
|
||||||
P 9800 4750
|
P 4500 6150
|
||||||
F 0 "D1" H 9800 5247 50 0000 C CNN
|
F 0 "D1" H 4500 6647 50 0000 C CNN
|
||||||
F 1 "LED_RGBA" H 9800 5156 50 0000 C CNN
|
F 1 "LED_RGBA" H 4500 6556 50 0000 C CNN
|
||||||
F 2 "" H 9800 4700 50 0001 C CNN
|
F 2 "" H 4500 6100 50 0001 C CNN
|
||||||
F 3 "~" H 9800 4700 50 0001 C CNN
|
F 3 "~" H 4500 6100 50 0001 C CNN
|
||||||
1 9800 4750
|
1 4500 6150
|
||||||
1 0 0 -1
|
1 0 0 -1
|
||||||
$EndComp
|
$EndComp
|
||||||
$Comp
|
$Comp
|
||||||
L power:+3.3V #PWR0117
|
L power:+3.3V #PWR0117
|
||||||
U 1 1 607C47BE
|
U 1 1 607C47BE
|
||||||
P 10200 4750
|
P 4900 6150
|
||||||
F 0 "#PWR0117" H 10200 4600 50 0001 C CNN
|
F 0 "#PWR0117" H 4900 6000 50 0001 C CNN
|
||||||
F 1 "+3.3V" H 10215 4923 50 0000 C CNN
|
F 1 "+3.3V" H 4915 6323 50 0000 C CNN
|
||||||
F 2 "" H 10200 4750 50 0001 C CNN
|
F 2 "" H 4900 6150 50 0001 C CNN
|
||||||
F 3 "" H 10200 4750 50 0001 C CNN
|
F 3 "" H 4900 6150 50 0001 C CNN
|
||||||
1 10200 4750
|
1 4900 6150
|
||||||
1 0 0 -1
|
1 0 0 -1
|
||||||
$EndComp
|
$EndComp
|
||||||
Wire Wire Line
|
Wire Wire Line
|
||||||
10000 4750 10200 4750
|
4700 6150 4900 6150
|
||||||
Text GLabel 6700 3500 2 50 Input ~ 0
|
Text GLabel 6700 3500 2 50 Input ~ 0
|
||||||
P_2
|
P_2
|
||||||
Text GLabel 6700 3600 2 50 Input ~ 0
|
Text GLabel 6700 3600 2 50 Input ~ 0
|
||||||
P_3
|
P_3
|
||||||
Text GLabel 6700 3700 2 50 Input ~ 0
|
Text GLabel 6700 3700 2 50 Input ~ 0
|
||||||
P_4
|
P_4
|
||||||
Text GLabel 9300 4550 0 50 Input ~ 0
|
Text GLabel 4000 5950 0 50 Input ~ 0
|
||||||
P_2
|
P_2
|
||||||
Text GLabel 9300 4750 0 50 Input ~ 0
|
Text GLabel 4000 6150 0 50 Input ~ 0
|
||||||
P_3
|
P_3
|
||||||
Text GLabel 9300 4950 0 50 Input ~ 0
|
Text GLabel 4000 6350 0 50 Input ~ 0
|
||||||
P_4
|
P_4
|
||||||
$Comp
|
$Comp
|
||||||
L Device:R R5
|
L Device:R R5
|
||||||
@ -818,9 +816,6 @@ Text GLabel 5300 4100 0 50 Input ~ 0
|
|||||||
ESP_GPIO_3_RXD
|
ESP_GPIO_3_RXD
|
||||||
Wire Wire Line
|
Wire Wire Line
|
||||||
5300 4100 5400 4100
|
5300 4100 5400 4100
|
||||||
NoConn ~ 6700 4000
|
|
||||||
NoConn ~ 6700 3900
|
|
||||||
NoConn ~ 6700 3800
|
|
||||||
NoConn ~ 1800 1600
|
NoConn ~ 1800 1600
|
||||||
NoConn ~ 1800 1700
|
NoConn ~ 1800 1700
|
||||||
NoConn ~ 1800 1800
|
NoConn ~ 1800 1800
|
||||||
@ -843,8 +838,6 @@ F 3 "~" H 7750 3400 50 0001 C CNN
|
|||||||
1 7750 3400
|
1 7750 3400
|
||||||
0 1 1 0
|
0 1 1 0
|
||||||
$EndComp
|
$EndComp
|
||||||
Wire Wire Line
|
|
||||||
7900 3400 8900 3400
|
|
||||||
$Comp
|
$Comp
|
||||||
L Device:R R15
|
L Device:R R15
|
||||||
U 1 1 60CE8759
|
U 1 1 60CE8759
|
||||||
@ -871,4 +864,144 @@ F 3 "~" H 1550 6100 50 0001 C CNN
|
|||||||
1 1550 6100
|
1 1550 6100
|
||||||
0 1 1 0
|
0 1 1 0
|
||||||
$EndComp
|
$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
|
$EndSCHEMATC
|
||||||
|
|||||||
213
src/app/app.ino
213
src/app/app.ino
@ -1,7 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Author : Anatole SCHRAMM-HENRY
|
* Author : Anatole SCHRAMM-HENRY
|
||||||
* Created the : 11/07/2021
|
* Created the : 11/07/2021
|
||||||
* This is a quick and dirty firmewire to receive and save the data in the database
|
* Last updated : 04/11/2025
|
||||||
|
* This is a quick and dirty gateway firmware to receive and save data from sensors to a database
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
@ -9,23 +10,45 @@
|
|||||||
#include <PCF8574.h>
|
#include <PCF8574.h>
|
||||||
#include <HttpClient.h>
|
#include <HttpClient.h>
|
||||||
#include "RF24.h"
|
#include "RF24.h"
|
||||||
|
#include <LoRa.h>
|
||||||
#include "definition.h"
|
#include "definition.h"
|
||||||
#include "credentials.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_1_CE 15 //chip enable
|
#define NRF_2_CE (16) //chip enable
|
||||||
#define NRF_2_CE 16 //chip enable
|
#define NRF_2_CS (4) //chip select
|
||||||
|
#define NRF_2_IRQ (PCF8574::P0)
|
||||||
|
|
||||||
#define NRF_1_CS 5 //chip select
|
#define NRF_CHANNEL (108) //0-125
|
||||||
#define NRF_2_CS 4 //chip select
|
#define NRF_PA_LEVEL (RF24_PA_MAX)
|
||||||
|
#define NRF_DATA_RATE (RF24_250KBPS) //250 Kb/s, 1 Mb/s & 2 Mb/s
|
||||||
|
|
||||||
#define CHAN 108 //0-125
|
#define RECV_CHECK 5000 //We test every 5s if we received something that did not trigger an IRQ (missed)
|
||||||
#define RECV_CHECK 5000 //We test every 5s if we received something
|
#define WIFI_CHECK_TIMEOUT 20000 //We check every 20 seconds the WiFi state
|
||||||
#define WIFI_CHECK_TIMEOUT 20000
|
#define PREVENTIVE_RESET_DELAY 18000000 //Every 5 hours the MCU is reseted, this SHOULD NOT be necessary
|
||||||
#define PREVENTIVE_RESET_DELAY 18000000 //Every 5 hours
|
|
||||||
|
/* 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)
|
||||||
|
|
||||||
uint8_t payload[32] = {0};
|
uint8_t payload[32] = {0};
|
||||||
DataPacket dp;
|
DataPacket packetHeader;
|
||||||
WeatherStationDataPacket wsdp;
|
WeatherStationDataPacket wsdp;
|
||||||
MailboxDataPacket mdp;
|
MailboxDataPacket mdp;
|
||||||
|
|
||||||
@ -44,25 +67,56 @@ uint32_t timeStamp(0), irqSaver(0), resetTimeStamp(0);
|
|||||||
uint32_t freeMem(0);
|
uint32_t freeMem(0);
|
||||||
uint16_t biggestContigMemBlock(0);
|
uint16_t biggestContigMemBlock(0);
|
||||||
uint8_t frag(0);
|
uint8_t frag(0);
|
||||||
int insertIntoDBError(0);
|
HttpClient::HttpQueryStatus insertIntoDBError(HttpClient::HttpQueryStatus::SUCCESS);
|
||||||
volatile boolean IRQFlag(false);
|
volatile boolean IRQFlag(false);
|
||||||
|
volatile boolean IRQIsLoRa(false);
|
||||||
boolean waitingForResetSignal(false), resetNow(false);
|
boolean waitingForResetSignal(false), resetNow(false);
|
||||||
|
|
||||||
IRAM_ATTR void NRFIRQsHandler(void *p)
|
void PCFPinMode(uint8_t pin, uint8_t mode)
|
||||||
{
|
{
|
||||||
Serial.println("NRF IRQs detected !");
|
PCF.pinMode(static_cast<PCF8574::Pin>(pin), static_cast<boolean>(mode));
|
||||||
*(boolean *)p = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
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);
|
||||||
|
*(boolean *)p = true;
|
||||||
|
|
||||||
|
/* If the IRQ pin is the DIO1, manually call the LoRa IRQ handler */
|
||||||
|
if(pinStates[7] == HIGH)
|
||||||
|
{
|
||||||
|
LoRa.handleDio0Rise();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
//We do not need to read on the serial bus
|
//We do not need to read on the serial bus
|
||||||
Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
|
Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println("\nSetup begin");
|
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 :
|
//We set the WiFi part up :
|
||||||
gotIp = WiFi.onStationModeGotIP(&(gotIpFunc));
|
gotIp = WiFi.onStationModeGotIP(&(gotIpFunc));
|
||||||
lostConnection = WiFi.onStationModeDisconnected(&(lostConnectionFunc));
|
lostConnection = WiFi.onStationModeDisconnected(&(lostConnectionFunc));
|
||||||
@ -72,6 +126,7 @@ void setup() {
|
|||||||
WiFi.softAPdisconnect(true);
|
WiFi.softAPdisconnect(true);
|
||||||
Serial.println("Connecting to the access point");
|
Serial.println("Connecting to the access point");
|
||||||
WiFi.begin(SSID, PWD);
|
WiFi.begin(SSID, PWD);
|
||||||
|
|
||||||
//We initialize the dictionary
|
//We initialize the dictionary
|
||||||
//These keys are used to post data for the weather station :
|
//These keys are used to post data for the weather station :
|
||||||
weatherStationPostData.add("accessCode", DictionaryHelper::StringEntity(ACCESS_CODE));
|
weatherStationPostData.add("accessCode", DictionaryHelper::StringEntity(ACCESS_CODE));
|
||||||
@ -84,7 +139,8 @@ void setup() {
|
|||||||
weatherStationPostData.add("humidity", DictionaryHelper::StringEntity(NULL));
|
weatherStationPostData.add("humidity", DictionaryHelper::StringEntity(NULL));
|
||||||
weatherStationPostData.add("compensated_humidity", DictionaryHelper::StringEntity(NULL));
|
weatherStationPostData.add("compensated_humidity", DictionaryHelper::StringEntity(NULL));
|
||||||
weatherStationPostData.add("htu_tmp", 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("accessCode", DictionaryHelper::StringEntity(ACCESS_CODE));
|
||||||
mailboxPostData.add("deviceType", DictionaryHelper::StringEntity(MAILBOX_DEV_TYPE));
|
mailboxPostData.add("deviceType", DictionaryHelper::StringEntity(MAILBOX_DEV_TYPE));
|
||||||
mailboxPostData.add("packetUID", DictionaryHelper::StringEntity(NULL));
|
mailboxPostData.add("packetUID", DictionaryHelper::StringEntity(NULL));
|
||||||
@ -98,9 +154,9 @@ void setup() {
|
|||||||
else
|
else
|
||||||
Serial.println("NRF 1 is detected");
|
Serial.println("NRF 1 is detected");
|
||||||
|
|
||||||
NRF_1.setChannel(CHAN);
|
NRF_1.setChannel(NRF_CHANNEL);
|
||||||
NRF_1.setPALevel(RF24_PA_MIN);
|
NRF_1.setPALevel(NRF_PA_LEVEL);
|
||||||
NRF_1.setDataRate(RF24_250KBPS);
|
NRF_1.setDataRate(NRF_DATA_RATE);
|
||||||
NRF_1.setRetries(8,15);
|
NRF_1.setRetries(8,15);
|
||||||
NRF_1.openReadingPipe(1, ADDR);
|
NRF_1.openReadingPipe(1, ADDR);
|
||||||
NRF_1.startListening();
|
NRF_1.startListening();
|
||||||
@ -111,9 +167,9 @@ void setup() {
|
|||||||
else
|
else
|
||||||
Serial.println("NRF 2 is detected");
|
Serial.println("NRF 2 is detected");
|
||||||
|
|
||||||
NRF_2.setChannel(CHAN);
|
NRF_2.setChannel(NRF_CHANNEL);
|
||||||
NRF_2.setPALevel(RF24_PA_MIN);
|
NRF_2.setPALevel(NRF_PA_LEVEL);
|
||||||
NRF_2.setDataRate(RF24_250KBPS);
|
NRF_2.setDataRate(NRF_DATA_RATE);
|
||||||
NRF_2.setRetries(8,15);
|
NRF_2.setRetries(8,15);
|
||||||
NRF_2.openReadingPipe(1, ADDR);
|
NRF_2.openReadingPipe(1, ADDR);
|
||||||
NRF_2.startListening();
|
NRF_2.startListening();
|
||||||
@ -121,20 +177,82 @@ void setup() {
|
|||||||
//Setting the I2C pins and the PCF8574
|
//Setting the I2C pins and the PCF8574
|
||||||
Wire.begin(0,2);
|
Wire.begin(0,2);
|
||||||
Serial.printf("PCF %s\n", PCF.begin() ? "found" : "not found");
|
Serial.printf("PCF %s\n", PCF.begin() ? "found" : "not found");
|
||||||
PCF.pinMode(PCF8574::P2, OUTPUT);
|
PCF.pinMode(LED_RED_PIN, OUTPUT);
|
||||||
PCF.pinMode(PCF8574::P3, OUTPUT);
|
PCF.pinMode(LED_GREEN_PIN, OUTPUT);
|
||||||
PCF.pinMode(PCF8574::P4, 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);
|
||||||
Serial.println("End setup");
|
Serial.println("End setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
//We check if we got and IRQ from one, both NRFs
|
//We check if we got and IRQ from one, both NRFs or the LoRa module
|
||||||
if(IRQFlag || (millis() - irqSaver > RECV_CHECK))
|
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;
|
bool tx_ok, tx_fail, rx_ready;
|
||||||
//We read the PCFs IO to check which NRF raised the IRQ :
|
//We read the PCFs IO to check which NRF raised the IRQ :
|
||||||
if(!PCF.digitalRead(PCF8574::P1)) //IRQs are active low
|
if(!PCF.digitalRead(NRF_1_IRQ)) //IRQs are active low
|
||||||
{
|
{
|
||||||
if(!IRQFlag)
|
if(!IRQFlag)
|
||||||
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IRQ MISSED FOR NRF 1");
|
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IRQ MISSED FOR NRF 1");
|
||||||
@ -153,9 +271,9 @@ void loop()
|
|||||||
Serial.printf("NRF 1 Received %u bytes with sig(%s) : \n",NRF_1.getPayloadSize(), NRF_1.testRPD()?"good":"bad");
|
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));
|
NRF_1.read(payload, sizeof(payload));
|
||||||
|
|
||||||
memcpy(&dp, payload, sizeof(dp));
|
memcpy(&packetHeader, payload, sizeof(packetHeader));
|
||||||
|
|
||||||
switch(dp.header)
|
switch(packetHeader.header)
|
||||||
{
|
{
|
||||||
case WEATHER_STATION:
|
case WEATHER_STATION:
|
||||||
{
|
{
|
||||||
@ -179,7 +297,7 @@ void loop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!PCF.digitalRead(PCF8574::P0)) //IRQs are active low
|
if(!PCF.digitalRead(NRF_2_IRQ)) //IRQs are active low
|
||||||
{
|
{
|
||||||
if(!IRQFlag)
|
if(!IRQFlag)
|
||||||
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IRQ MISSED FOR NRF 2");
|
Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IRQ MISSED FOR NRF 2");
|
||||||
@ -198,9 +316,9 @@ void loop()
|
|||||||
Serial.printf("NRF 2 Received %u bytes with sig(%s) : \n",NRF_2.getPayloadSize(), NRF_2.testRPD()?"good":"bad");
|
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));
|
NRF_2.read(payload, sizeof(payload));
|
||||||
|
|
||||||
memcpy(&dp, payload, sizeof(dp));
|
memcpy(&packetHeader, payload, sizeof(packetHeader));
|
||||||
|
|
||||||
switch(dp.header)
|
switch(packetHeader.header)
|
||||||
{
|
{
|
||||||
case WEATHER_STATION:
|
case WEATHER_STATION:
|
||||||
{
|
{
|
||||||
@ -244,11 +362,12 @@ void loop()
|
|||||||
//Here we check if we are still connected
|
//Here we check if we are still connected
|
||||||
if(millis() - timeStamp > WIFI_CHECK_TIMEOUT)
|
if(millis() - timeStamp > WIFI_CHECK_TIMEOUT)
|
||||||
{
|
{
|
||||||
//PCF.togglePin(PCF8574::P2);
|
|
||||||
//PCF.togglePin(PCF8574::P3);
|
|
||||||
//PCF.togglePin(PCF8574::P4);
|
|
||||||
ESP.getHeapStats(&freeMem, &biggestContigMemBlock, &frag);
|
ESP.getHeapStats(&freeMem, &biggestContigMemBlock, &frag);
|
||||||
printf("Memory Info :\n - Free Mem > %u\n - Heap frag > %u\n - Max block > %u\nSign strength : %d\n", freeMem, frag, biggestContigMemBlock,WiFi.RSSI());
|
printf("Memory Info :\n - Free Mem > %u\n - Heap frag > %u\n - Max block > %u\nWiFi RSSI : %d\n",
|
||||||
|
freeMem, frag,
|
||||||
|
biggestContigMemBlock,
|
||||||
|
WiFi.RSSI());
|
||||||
|
|
||||||
Serial.println("Checking wifi link : ");
|
Serial.println("Checking wifi link : ");
|
||||||
if(WiFi.isConnected())
|
if(WiFi.isConnected())
|
||||||
{
|
{
|
||||||
@ -270,7 +389,7 @@ void loop()
|
|||||||
resetTimeStamp = millis();
|
resetTimeStamp = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
if((waitingForResetSignal && resetNow) || insertIntoDBError == -125)
|
if((waitingForResetSignal && resetNow) || insertIntoDBError == HttpClient::HttpQueryStatus::ERR_CONN)
|
||||||
{
|
{
|
||||||
ESP.reset();
|
ESP.reset();
|
||||||
}
|
}
|
||||||
@ -291,10 +410,10 @@ void lostConnectionFunc(const WiFiEventStationModeDisconnected &event)
|
|||||||
Serial.println("Lost connection, will try to reconnect ...");
|
Serial.println("Lost connection, will try to reconnect ...");
|
||||||
}
|
}
|
||||||
|
|
||||||
int insertIntoDB(WeatherStationDataPacket *p)
|
HttpClient::HttpQueryStatus insertIntoDB(WeatherStationDataPacket *p)
|
||||||
{
|
{
|
||||||
char buffer[100] = "";
|
char buffer[100] = "";
|
||||||
int result(0);
|
HttpClient::HttpQueryStatus result(HttpClient::HttpQueryStatus::SUCCESS);
|
||||||
//We get the values and put it in our dictionary
|
//We get the values and put it in our dictionary
|
||||||
sprintf(buffer ,"%u", p->id);
|
sprintf(buffer ,"%u", p->id);
|
||||||
weatherStationPostData("packetUID")->setString(buffer);
|
weatherStationPostData("packetUID")->setString(buffer);
|
||||||
@ -320,7 +439,7 @@ int insertIntoDB(WeatherStationDataPacket *p)
|
|||||||
sprintf(buffer, "%f", p->htuTemp);
|
sprintf(buffer, "%f", p->htuTemp);
|
||||||
weatherStationPostData("htu_tmp")->setString(buffer);
|
weatherStationPostData("htu_tmp")->setString(buffer);
|
||||||
|
|
||||||
if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &weatherStationPostData)) == 0)
|
if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &weatherStationPostData)) == HttpClient::HttpQueryStatus::SUCCESS)
|
||||||
{
|
{
|
||||||
Serial.println("Data posted successfully");
|
Serial.println("Data posted successfully");
|
||||||
HttpClient::HTTP_CODE response = DBHost.isReplyAvailable(2000);
|
HttpClient::HTTP_CODE response = DBHost.isReplyAvailable(2000);
|
||||||
@ -370,10 +489,10 @@ void debugStruct(WeatherStationDataPacket *p)
|
|||||||
Serial.println(" *C");
|
Serial.println(" *C");
|
||||||
}
|
}
|
||||||
|
|
||||||
int insertIntoDB(MailboxDataPacket *p)
|
HttpClient::HttpQueryStatus insertIntoDB(MailboxDataPacket *p)
|
||||||
{
|
{
|
||||||
char buffer[100] = "";
|
char buffer[100] = "";
|
||||||
int result(0);
|
HttpClient::HttpQueryStatus result(HttpClient::HttpQueryStatus::SUCCESS);
|
||||||
//We get the values and put it in our dictionary
|
//We get the values and put it in our dictionary
|
||||||
sprintf(buffer ,"%u", p->id);
|
sprintf(buffer ,"%u", p->id);
|
||||||
mailboxPostData("packetUID")->setString(buffer);
|
mailboxPostData("packetUID")->setString(buffer);
|
||||||
@ -396,7 +515,7 @@ int insertIntoDB(MailboxDataPacket *p)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &mailboxPostData)) == 0)
|
if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &mailboxPostData)) == HttpClient::HttpQueryStatus::SUCCESS)
|
||||||
{
|
{
|
||||||
Serial.println("Data posted successfully");
|
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.
|
HttpClient::HTTP_CODE response = DBHost.isReplyAvailable(5000); //We increase the timeout because sending a mail on the server side takes some time.
|
||||||
|
|||||||
@ -25,11 +25,13 @@ class PCF8574
|
|||||||
void togglePin(Pin pin);
|
void togglePin(Pin pin);
|
||||||
// Reset the IRQ by doing a dummy read
|
// Reset the IRQ by doing a dummy read
|
||||||
void resetIRQ();
|
void resetIRQ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TwoWire &_twc;
|
TwoWire &_twc;
|
||||||
uint8_t _address;
|
uint8_t _address;
|
||||||
uint8_t _pinConfig;
|
uint8_t _pinConfig;
|
||||||
uint8_t _pddr;
|
uint8_t _pddr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -347,6 +347,22 @@ int LoRaClass::read()
|
|||||||
return readRegister(REG_FIFO);
|
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()
|
int LoRaClass::peek()
|
||||||
{
|
{
|
||||||
if (!available()) {
|
if (!available()) {
|
||||||
|
|||||||
@ -54,6 +54,7 @@ public:
|
|||||||
// from Stream
|
// from Stream
|
||||||
virtual int available();
|
virtual int available();
|
||||||
virtual int read();
|
virtual int read();
|
||||||
|
virtual int read(uint8_t *buffer, size_t len);
|
||||||
virtual int peek();
|
virtual int peek();
|
||||||
virtual void flush();
|
virtual void flush();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user