-
Notifications
You must be signed in to change notification settings - Fork 0
/
GatewayV5-ESP32-Azurev2.ino
59 lines (40 loc) · 1.29 KB
/
GatewayV5-ESP32-Azurev2.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
/*
Gateway - Adafruit Feather ESP32
Purpose:
Acts as Master Node and receives data from 2.4 gHz Network Mesh Nodes.
Converts the data received from a node to a JSON package.
JSON string gets sent to a MQTT Server.
Use:
Configure Credentials and Radio Setup in NetworkManager.h
Version 4 15/2-2018
Created by Poja Shad & Arthur Payne
FINAL VERSION
*/
#include <SPI.h>
#include "NetworkManager.h"
NetworkManager networkManager;
uint32_t displayTimer = 0;
void setup() {
Serial.begin(115200);
delay(2000);
networkManager.init(); // 1.Set Master Node/Starts Mesh - 2.Connects to WiFi- 3.Starts Timeclient - 4.Connects To Azure
}
void loop() {
// Reconnect to WiFi if it drops.
if ( WiFi.status() != WL_CONNECTED ) {
Serial.println(networkManager.timeClient.getFormattedTime());
networkManager.connectWiFi();
networkManager.connectCloud();
}
networkManager.updateTime(); // Get fresh/updated time from server
networkManager.updateMesh();
networkManager.updateDHCP();
// If the Master Node is connected to the RF Mesh, receive payload and send to cloud
if (networkManager.network.available()) {
networkManager.sendPayloadToCloud();
}
if (millis() - displayTimer > 3000) {
displayTimer = millis();
networkManager.printInfo();
}
}