-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoraReceiver.ino
More file actions
78 lines (57 loc) · 1.74 KB
/
Copy pathLoraReceiver.ino
File metadata and controls
78 lines (57 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <LoraReceiver.h>
#include <SPI.h>
MeasureData measureData;
String HTTPPayload;
unsigned long lastActivityTime = 0;
void setup()
{
initializeSerialCommunication();
setCpuFrequencyMhz(80); // MHz
configureGPIO();
connectToWifi(ssid, password);
SPI.begin(SPI_SCLK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN, SPI_CS0_PIN); // set SPI pins
LoRa.setSPI(SPI);
LoRa.setPins(SPI_CS0_PIN, RFM95_RESET_PIN, RFM95_DIO0_PIN);
if (!LoRa.begin(RFM95_COMM_FREQ))
{
Serial.println("Starting LoRa failed!");
while (1);
}
setLoRaParametersFor(POWER_MODE);
LoRa.onCadDone(onCadDone); // register channel activity detection callback
LoRa.onReceive(onReceive); // register packet receive callback
LoRa.channelActivityDetection(); // put the radio into CAD mode
esp_sleep_enable_timer_wakeup(getLightSleepTime_uS(RFM95_SEND_RATE));
lastActivityTime = millis(); // now
}
void loop()
{
if (isPacketReceived)
{
isPacketReceived = false;
lastActivityTime = millis();
if(isDebugMode())
{
playBeepingSound();
}
JsonDocument jsonBuffer;
JsonArray JSONArrayPacket = jsonBuffer.to<JsonArray>();
decodePacketToJsonArray(JSONArrayPacket);
parseJsonArrayPacketToMeasureDataStruct(JSONArrayPacket, measureData);
createPayloadForHTTPRequest(JSONArrayPacket, HTTPPayload);
if (isDebugMode())
{
printMeasureDataToSerialMonitor(measureData);
}
sendPayloadViaHTTPRequest(HTTPPayload);
#if LIGHT_SLEEP_ENABLED
// disconnect from network and turn the radio off
WiFi.disconnect(true);
esp_light_sleep_start();
// after wakeup
connectToWifi(ssid, password);
#endif
LoRa.channelActivityDetection();
}
handleInactivity(lastActivityTime);
}