-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkManager.h
112 lines (93 loc) · 2.69 KB
/
NetworkManager.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
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
/** NetworkManager Class -
Configure Your Credentials Here
*/
#include <Arduino.h>
#include "Base64.h"
#include "sha256.h"
#include <WiFiClientSecure.h>
#include "Hash.h"
#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include "PubSubClient.h"
#include "NTPClient.h"
#include <WiFiUdp.h>
#include <SHA256.h>
#include <TimeLib.h>
class NetworkManager {
public:
NetworkManager();
/* LIBRARY CONSTRUCTORS */
RF24 radio;
RF24Network network;
RF24Mesh mesh;
WiFiClientSecure wifiClient;
PubSubClient client;
NTPClient timeClient;
WiFiUDP ntpUDP;
SHA256 sha256;
int status;
int clientState;
/* RADIO */
int CE = 33;
int CS = 27;
/* CREDENTIALS ***/
/** --------- AZURE ---------- */
// -- Server
String server = "Acando-IoT.azure-devices.net";
int port = 8883;
// Device INFO clientId = deviceID
String clientId = "CLIENTID";
String hub_user = "USER";
const char* host;
char* key;
const char* deviceId;
// default topic feed for publishing is "devices/<myCoolDevice>/messages/events/"
String pubEndpoint = "devices/Acando-Stockholm/messages/events/";
String subEndpoint = "devices/Acando-Stockholm/messages/devicebound/#";
/** ^^^^^^^ AZURE ^^^^^^^^^^^ */
/** NETWORK MANAGER FUNCTIONS **/
void init();
void sendPayloadToCloud();
void connectWiFi();
void connectCloud();
void updateTime();
void updateMesh();
void updateDHCP();
void printInfo();
void callback(char* topic, byte* payload, unsigned int length);
String errorCodes(int errorCode);
void setConnectionString(String cs);
time_t sasExpiryTime = 0;
int sasExpiryPeriodInSeconds = 60 * 60 * 24; // SAS TOKEN EXPIRY
protected:
String urlEncode(const char* msg);
const char* GetStringValue(String value);
private:
const char* connectionString = "PUTCONNECTIONSTRING";
bool generateSas();
String splitStringByIndex(String data, char separator, int index);
char* format(const char *input, const char *value);
char* format(const char *input, const char *value1, const char *value2);
String createSas(char* key, String url);
String url = "URL";
String newSas;
const char* cUrl;
/*** WIFI CREDENTIALS ***/
String ssid = "SSID"; /*** your network SSID (name) ***/
String pass = "PASS"; /*** your network password ***/
///// --- Payload
float incommingDataArray[7];
String nodeID;
String temp;
String hum;
String voc;
String c02;
String motion;
String sound;
String error;
String jsonString;
String payload;
int count = 0;
long lastReconnectAttempt;
};