-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonem2m.ino
45 lines (34 loc) · 1.06 KB
/
onem2m.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
#include <HTTPClient.h>
#include "constants.h"
long randNumber;
HTTPClient http;
String server;
void publish_Onem2m(unsigned long epochTime, float sensor_value){
String data;
if (HTTPS){
server = "https://" + String() + CSE_IP + ":" + String() + CSE_PORT + String() + OM2M_MN;
}
else{
server = "http://" + String() + CSE_IP + ":" + String() + CSE_PORT + String() + OM2M_MN;
}
http.begin(server + String() + OM2M_AE + "/" + OM2M_DATA_CONT + "/");
http.addHeader("X-M2M-Origin", OM2M_ORGIN);
http.addHeader("Content-Type", "application/json;ty=4");
http.addHeader("Content-Length", "100");
data = "[" + String(epochTime) + ", " + String(sensor_value) + + "]";
String req_data = String() + "{\"m2m:cin\": {"
+
"\"con\": \"" + data + "\","
+
"\"lbl\": \"" + "V1.0.0" + "\","
//+ "\"rn\": \"" + "cin_"+String(i++) + "\","
+
"\"cnf\": \"text\""
+
"}}";
int code = http.POST(req_data);
http.end();
Serial.println(code);
prev_millis = millis();
delay(500);
}