-
Notifications
You must be signed in to change notification settings - Fork 2
/
milkcocoa_esp8266_tout.ino
72 lines (50 loc) · 1.77 KB
/
milkcocoa_esp8266_tout.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <ESP8266WiFi.h>
#include <Milkcocoa.h>
/************************* WiFi Access Point *********************************/
#define WLAN_SSID "...SSID..."
#define WLAN_PASS "...PASS..."
/************************* Your Milkcocoa Setup *********************************/
#define MILKCOCOA_APP_ID "...YOUR_MILKCOCOA_APP_ID..."
#define MILKCOCOA_DATASTORE "esp8266/tout"
/************* Milkcocoa Setup (you don't need to change this!) ******************/
#define MILKCOCOA_SERVERPORT 1883
/************ Global State (you don't need to change this!) ******************/
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
const char MQTT_SERVER[] PROGMEM = MILKCOCOA_APP_ID ".mlkcca.com";
const char MQTT_CLIENTID[] PROGMEM = __TIME__ MILKCOCOA_APP_ID;
Milkcocoa milkcocoa = Milkcocoa(&client, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID);
void onpush(DataElement *elem) {
Serial.println("onpush");
Serial.println(elem->getInt("v"));
};
void setupWiFi() {
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(115200);
delay(10);
Serial.println(F("Milkcocoa SDK demo"));
setupWiFi();
Serial.println( milkcocoa.on(MILKCOCOA_DATASTORE, "push", onpush) );
};
void loop() {
milkcocoa.loop();
int val = analogRead(A0);
Serial.println(String(val));
DataElement elem = DataElement();
elem.setValue("v", val);
milkcocoa.push(MILKCOCOA_DATASTORE, &elem);
delay(7000);
};