-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApoc_Receiver.ino
61 lines (51 loc) · 1.34 KB
/
Apoc_Receiver.ino
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
#include <SPI.h>
#include "FS.h"
#include "RTClib.h"
#include <LoRa.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
const char* NETWORK_ID = "WD"; //Network identifier for the sensor group - MUST BE CHANGED BY USER
#define LOGGING 1 //Changing this to 0 will stop the system from recording logs
#define LORA_FREQUENCY 433E6 //LoRa radio frequency in Hz (433 MHz in this case)
struct SensorData {
char networkID[5];
char nodeID[5];
unsigned long sequence;
unsigned long timestamp;
float temperature;
float humidity;
float light;
float soilMoisture;
float batteryVoltage;
char checksum[5];
};
RTC_DS1307 rtc;
void setup() {
Serial.begin(115200);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
LoRa_init();
Flash_Init();
RTC_init(rtc);
BLE_init();
// Create FreeRTOS tasks for LoRa and BLE services
xTaskCreate(LoRa_services, "LoRa Task", 8192, NULL, 2, NULL);
xTaskCreate(BLE_services, "BLE Task", 8192, NULL, 1, NULL);
writeToLogs("System booted up");
}
void loop() {
if (Serial.available()) {
String command = Serial.readStringUntil('\n');
handleCommand(command);
}
}
void indicateError() {
for (int i = 0; i < 5; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
}