source: rtos_arduino/trunk/arduino_lib/libraries/Milkcocoa_Arduino_SDK/examples/milkcocoa_esp8266_tout/milkcocoa_esp8266_tout.ino@ 144

Last change on this file since 144 was 144, checked in by ertl-honda, 8 years ago

Milkcocoa用のMQTTライブラリの追加と,ESP8266用ライブラリの名称変更.

File size: 2.2 KB
RevLine 
[144]1#include "ESP8266.h"
2#include "Milkcocoa.h"
3#include "Client_ESP8266.h"
4
5extern "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.
27ESP8266Client wifi;
28
29const char MQTT_SERVER[] PROGMEM = MILKCOCOA_APP_ID ".mlkcca.com";
30const char MQTT_CLIENTID[] PROGMEM = __TIME__ MILKCOCOA_APP_ID;
31
32Milkcocoa milkcocoa = Milkcocoa(&wifi, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID);
33
34void 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
75void 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
88void onpush(DataElement elem) {
89 Serial.println("onpush");
90 Serial.println(elem.getInt("v"));
91};
Note: See TracBrowser for help on using the repository browser.