-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainNode.h
56 lines (45 loc) · 1.21 KB
/
MainNode.h
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
#ifndef MAIN_NODE_H
#define MAIN_NODE_H
#include <WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include "PreInstalledNode.h"
const int MAX_SENSOR_NODES = 1;
const unsigned long WIFI_CONNECT_DELAY = 5000;
const unsigned long MQTT_CONNECT_DELAY = 5000;
struct Network_Status
{
Sensor_Node data;
Student_Node connected_nodes[MAX_STUDENT_NODES];
bool status = false;
long time;
};
class MainNode : public PreInstalledNode
{
public:
MainNode(uint16_t node, int channel);
void init() override;
void checkMQTTConnection();
void receivePayload() override;
void checkNodesConnection() override;
void publishNetworkStatus();
private:
Network_Status network_status[MAX_SENSOR_NODES];
WiFiClient espClient;
PubSubClient client;
unsigned long last_sent;
char *_ssid;
char *_wifiPassword;
char *_server;
short _port;
char *_topic;
void receiveKeepAlive(RF24NetworkHeader &header) override;
void setupWiFi();
void setupMQTT();
void receiveReadings(RF24NetworkHeader &header);
Sensor_Node deserializeSensorNode(uint8_t* buffer);
void receiveBeginFlag(RF24NetworkHeader &header);
void receiveNodeID(RF24NetworkHeader &header);
int decimalToOctal(uint16_t octalNumber);
};
#endif