-
Notifications
You must be signed in to change notification settings - Fork 0
/
orion-node.ino
executable file
·183 lines (147 loc) · 3.61 KB
/
orion-node.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Orion Node
Firmware for the Node IoT devices
----------------------------------
Author: Bryce Narciso C. Mercines
*/
// Import required libraries
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>
//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
// Most performant ISM Band (Philippines) good RSSI
#define BAND 923E6
//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Initialize Screen
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);
// device unique ID (can be changed)
String UID = "IO-00001";
String LoRaData;
// Replace with your network credentials
const char *ssid = "Orion_Node_1";
const char *password = "";
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
const char index_html[] PROGMEM = R"rawliteral(
<p>Orion Node</p>
)rawliteral";
void sendData(String LORA_DATA)
{
LoRa.beginPacket();
LoRa.print(LORA_DATA);
LoRa.endPacket();
}
void echoMechanism()
{
// testing echo
int packetSize = LoRa.parsePacket();
if (packetSize)
{
//received a packet
//read packet
while (LoRa.available())
{
LoRaData = LoRa.readString();
sendData(LoRaData);
delay(2000);
}
}
else
{
delay(3000);
}
}
void setup()
{
// Serial Port for communicating to GPS Module
Serial.begin(9600);
//reset OLED display via software
pinMode(OLED_RST, OUTPUT);
digitalWrite(OLED_RST, LOW);
delay(20);
digitalWrite(OLED_RST, HIGH);
//initialize OLED
Wire.begin(OLED_SDA, OLED_SCL);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false))
{ // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.println("ORION NODE");
display.println("NODE ID: " + UID);
display.display();
//SPI LoRa pins
SPI.begin(SCK, MISO, MOSI, SS);
//setup LoRa transceiver module
LoRa.setPins(SS, RST, DIO0);
if (!LoRa.begin(BAND))
{
// Starting LoRa Fails
while (1)
;
}
// Remove the password parameter, if you want the AP (Access Point) to be open
WiFi.softAP(ssid, password);
// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send_P(200, "text/html", index_html);
});
// for sending data (test)
server.on("/report", HTTP_GET, [](AsyncWebServerRequest *request) {
// try and capture parameters
int paramsNr = request->params();
for (int i = 0; i < paramsNr; i++)
{
AsyncWebParameter *p = request->getParam(i);
String webData = p->value();
String formData = webData;
sendData(formData);
}
request->send_P(200, "text/plain", "recieved");
});
// Start server
server.begin();
}
void loop()
{
// for echoing data
// testing echo
int packetSize = LoRa.parsePacket();
Serial.println("pz: " + packetSize);
if (packetSize)
{
//received a packet
//read packet
while (LoRa.available())
{
LoRaData = LoRa.readString();
}
sendData("e1:" + LoRaData);
Serial.println("e1:" + LoRaData);
}
// node beacon test
// sendData("Data from Node 1");
// Serial.println("Sending data from:" + UID);
}