-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathESP.ino
52 lines (44 loc) · 1.48 KB
/
ESP.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
/****************************************
* Include Libraries
****************************************/
#include "UbidotsESPMQTT.h"
/****************************************
* Define Constants
****************************************/
#define TOKEN "....." // Your Ubidots TOKEN
#define WIFINAME "...." //Your SSID
#define WIFIPASS "....." // Your Wifi Pass
Ubidots client(TOKEN);
/****************************************
* Auxiliar Functions
****************************************/
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i=0;i<length;i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}
/****************************************
* Main Functions
****************************************/
void setup() {
// put your setup code here, to run once:
//client.ubidotsSetBroker("industrial.api.ubidots.com"); // Sets the broker properly for the industrial account
client.setDebug(true); // Pass a true or false bool value to activate debug messages
Serial.begin(115200);
client.wifiConnection(WIFINAME, WIFIPASS);
client.begin(callback);
}
void loop() {
// put your main code here, to run repeatedly:
if(!client.connected()){
client.reconnect();
}
float value1 = analogRead(A0);
client.add("temperature", value1);
client.ubidotsPublish("my-new-device");
client.loop();
}