Milkcocoa ESP8266 SDK
C++ C
Latest commit 2af29f9 Dec 21, 2016 @syuhei176 syuhei176 committed on GitHub Update README.md
Permalink
Failed to load latest commit information.
aJson Fix examples Oct 17, 2015
examples Refactor examples Mar 6, 2016
include first commit Oct 13, 2015
.gitignore first commit Oct 13, 2015
Adafruit_MQTT.cpp first commit Oct 13, 2015
Adafruit_MQTT_Client.cpp first commit Oct 13, 2015
Milkcocoa.cpp Added ping Dec 21, 2016
Milkcocoa.h Added ping Dec 21, 2016
README.md Update README.md Dec 21, 2016
aJSON.cpp first commit Oct 13, 2015
library.properties Update library.properties Dec 16, 2015
stringbuffer.c first commit Oct 13, 2015

README.md

Milkcocoa ESP8266 SDK

Milkcocoa SDK working on Arduino core for ESP8266.

Works with the ESP8266 Arduino platforms, and anything that supports Arduino's Client interface.

How To Use

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
};

Using API Key

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");

onメソッドでイベント監視だけ行う場合

接続を維持するために、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
};

Examples

LICENSE

MIT

以下はCopyright (c) 2015 Technical Rockstars.

  • Milkcocoa.h
  • Milkcocoa.cpp

Using