1 | #include "ESP8266.h"
|
---|
2 | #include "Milkcocoa.h"
|
---|
3 | #include "Client_ESP8266.h"
|
---|
4 |
|
---|
5 | extern "C" {
|
---|
6 | #include "user_interface.h"
|
---|
7 | }
|
---|
8 |
|
---|
9 | /************************* WiFi Access Point *********************************/
|
---|
10 |
|
---|
11 | #define WLAN_SSID "...SSID..."
|
---|
12 | #define WLAN_PASS "...PASS..."
|
---|
13 |
|
---|
14 |
|
---|
15 | /************************* Your Milkcocoa Setup *********************************/
|
---|
16 |
|
---|
17 | #define MILKCOCOA_APP_ID "...YOUR_MILKCOCOA_APP_ID..."
|
---|
18 | #define MILKCOCOA_DATASTORE "esp8266/tout"
|
---|
19 |
|
---|
20 | /************* Milkcocoa Setup (you don't need to change this!) ******************/
|
---|
21 |
|
---|
22 | #define MILKCOCOA_SERVERPORT 1883
|
---|
23 |
|
---|
24 | /************ Global State (you don't need to change this!) ******************/
|
---|
25 |
|
---|
26 | // Create an ESP8266Client class to connect to the MQTT server.
|
---|
27 | ESP8266Client wifi;
|
---|
28 |
|
---|
29 | const char MQTT_SERVER[] PROGMEM = MILKCOCOA_APP_ID ".mlkcca.com";
|
---|
30 | const char MQTT_CLIENTID[] PROGMEM = __TIME__ MILKCOCOA_APP_ID;
|
---|
31 |
|
---|
32 | Milkcocoa milkcocoa = Milkcocoa(&wifi, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID);
|
---|
33 |
|
---|
34 | void setup() {
|
---|
35 | Serial.begin(115200);
|
---|
36 | delay(10);
|
---|
37 |
|
---|
38 | Serial.println(F("Milkcocoa SDK demo"));
|
---|
39 |
|
---|
40 | wifi.begin(Serial5, 115200);
|
---|
41 |
|
---|
42 | Serial.print("FW Version:");
|
---|
43 | Serial.println(wifi.getVersion().c_str());
|
---|
44 |
|
---|
45 | if (wifi.setOprToStation()) {
|
---|
46 | Serial.print("to station ok\r\n");
|
---|
47 | } else {
|
---|
48 | Serial.print("to station err\r\n");
|
---|
49 | }
|
---|
50 |
|
---|
51 | if (wifi.joinAP(WLAN_SSID, WLAN_PASS)) {
|
---|
52 | Serial.print("Join AP success\r\n");
|
---|
53 | Serial.print("IP: ");
|
---|
54 | Serial.println(wifi.getLocalIP().c_str());
|
---|
55 | } else {
|
---|
56 | Serial.print("Join AP failure\r\n");
|
---|
57 | }
|
---|
58 |
|
---|
59 | if (wifi.disableMUX()) {
|
---|
60 | Serial.print("single ok\r\n");
|
---|
61 | } else {
|
---|
62 | Serial.print("single err\r\n");
|
---|
63 | }
|
---|
64 |
|
---|
65 | if(milkcocoa->on(MILKCOCOA_DATASTORE, "push", onpush)){
|
---|
66 | Serial.println("milkcocoa on sucesss");
|
---|
67 | }
|
---|
68 | else {
|
---|
69 | Serial.println("milkcocoa on failure");
|
---|
70 | }
|
---|
71 | };
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 | void loop() {
|
---|
76 | milkcocoa.loop();
|
---|
77 |
|
---|
78 | uint ADC_Value = 0;
|
---|
79 | ADC_Value = system_adc_read();
|
---|
80 |
|
---|
81 | DataElement elem = DataElement();
|
---|
82 | elem.setValue("v", (int)ADC_Value);
|
---|
83 | milkcocoa.push(MILKCOCOA_DATASTORE, elem);
|
---|
84 |
|
---|
85 | delay(7000);
|
---|
86 | };
|
---|
87 |
|
---|
88 | void onpush(DataElement elem) {
|
---|
89 | Serial.println("onpush");
|
---|
90 | Serial.println(elem.getInt("v"));
|
---|
91 | };
|
---|