-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiFraSDK.h
More file actions
65 lines (50 loc) · 1.61 KB
/
Copy pathiFraSDK.h
File metadata and controls
65 lines (50 loc) · 1.61 KB
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
#ifndef HARDWAREPLATFORM_H
#define HARDWAREPLATFORM_H
#include "HardWarePlatform.h"
#endif // HARDWAREPLATFORM_H
#include <ArduinoJson.h>
#include "Client.h"
#include "Stream.h"
#include <WiFi.h>
#include <PubSubClient.h>
// for convenience
// using json = nlohmann::json;
#ifndef IFRA_SERVER
#define IFRA_SERVER "mqtt.ifra.io"
#endif
#ifndef NTP_SERVER
#define NTP_SERVER "asia.pool.ntp.org"
#endif
#ifndef MQTT_PORT
#define MQTT_PORT 1883
#endif
#define ON 1
#define OFF 0
const size_t _capacity = JSON_ARRAY_SIZE(500) + JSON_OBJECT_SIZE(10);
class iFraSDK
{
private:
HardWarePlatform* hardWarePlatform_;
char* channel_;
char* username_;
char* password_;
char* server_;
char* _base_name;
char* _base_unit;
int _recordCount;
unsigned long int _base_time;
Client *client_;
PubSubClient mqtt_client_;
public:
iFraSDK();
iFraSDK(HardWarePlatform* hardWarePlatform, char* channel, char* username, char* password);
iFraSDK(HardWarePlatform* hardWarePlatform ,char* channel, char* username, char* password, char* server) ;
void addSensor(char * sensor_name, char * unit, float value);
void addActuator(void (*callbackFunc)(char * actuator_name, int * value , char * topic, byte * payload, unsigned int length)); //int
void addActuator(void (*callbackFunc)(char * actuator_name, float * value , char * topic, byte * payload, unsigned int length)); //float
void addEventActuator(char * actuator_name, int value , void (*callbackFunc)(char* actuator_name, float* value));
void send();
void wifiConnection();
bool connected();
void reconnect();
};