Milkcocoa SDK working on Arduino core for ESP8266.
Works with the ESP8266 Arduino platforms, and anything that supports Arduino's Client interface.
Include library(#include <Milkcocoa.h>
), and write a code like below.
// 'client' is Ethernet/WiFi Client
Milkcocoa milkcocoa = Milkcocoa(&client, "milkcocoa_app_id.mlkcca.com", 1883, "milkcocoa_app_id", "mqtt_client_id");
void setup() {
//"on" API was able to call in setup
milkcocoa.on("milkcocoa_datastore_name", "push", onpush);
}
void loop() {
//milkcocoa.loop must be called in loop()
milkcocoa.loop();
//push
DataElement elem = DataElement();
elem.setValue("name", "Milk");
elem.setValue("age", 35);
milkcocoa.push("milkcocoa_datastore_name", &elem);
delay(10000);
}
void onpush(DataElement *elem) {
Serial.println(elem->getString("name"));
Serial.println(elem->getInt("age"));
// Output:
// Milk
// 35
};
If you use Milkcocoa API Key Authantication, please use createWithApiKey
.
Milkcocoa *milkcocoa = Milkcocoa::createWithApiKey(&client, "milkcocoa_app_id.mlkcca.com", 1883, "milkcocoa_app_id", "mqtt_client_id", "API_KEY", "API_SECRET");
接続を維持するために、10秒から20秒間隔でpingを送信する必要があります。
void setup() {
//"on" API was able to call in setup
milkcocoa.on("milkcocoa_datastore_name", "push", onpush);
}
void loop() {
//milkcocoa.loop must be called in loop()
milkcocoa.loop();
milkcocoa.ping()
delay(10000);
}
void onpush(DataElement *elem) {
Serial.println(elem->getString("name"));
Serial.println(elem->getInt("age"));
// Output:
// Milk
// 35
};
- Simple ESP8266 Example: simple test of
push()
andon("push")
. - ESP8266 TOUT Example: get sensor data from TOUT of ESP8266
- ESP8266 API Key Authantication Example: auth with Milkcocoa API Key
MIT
以下はCopyright (c) 2015 Technical Rockstars.
- Milkcocoa.h
- Milkcocoa.cpp