[144] | 1 | Milkcocoa Arduino SDK
|
---|
| 2 | =====
|
---|
| 3 |
|
---|
| 4 | [Milkcocoa](https://mlkcca.com/) SDK for Arduino with ESP8266(use AT).
|
---|
| 5 |
|
---|
| 6 | Works with Arduino M0 & M0 pro with ESP8266.
|
---|
| 7 |
|
---|
| 8 | To use thie library, you also download and install ESP8266 library
|
---|
| 9 | (https://github.com/exshonda/ESP8266_Arduino_AT)
|
---|
| 10 |
|
---|
| 11 | ## How To Use
|
---|
| 12 |
|
---|
| 13 | Include libraries(`#include <Milkcocoa.h> and #include "ESP8266.h" and #include "Client_ESP8266.h"`), and write a code like below.
|
---|
| 14 |
|
---|
| 15 | ```
|
---|
| 16 | ESP8266Client wifi;
|
---|
| 17 | Milkcocoa milkcocoa = Milkcocoa(&wifi, "milkcocoa_app_id.mlkcca.com", 1883, "milkcocoa_app_id", "mqtt_client_id");
|
---|
| 18 |
|
---|
| 19 | void setup() {
|
---|
| 20 | //"Serial5" Serial port connected to ESP8266.
|
---|
| 21 | wifi.begin(Serial5, 115200);
|
---|
| 22 |
|
---|
| 23 | //Set ESP8266 as Station mode.
|
---|
| 24 | if (wifi.setOprToStation()) {
|
---|
| 25 | Serial.print("to station ok\r\n");
|
---|
| 26 | } else {
|
---|
| 27 | Serial.print("to station err\r\n");
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | //Connect to Wifi AP
|
---|
| 31 | if (wifi.joinAP(WLAN_SSID, WLAN_PASSWORD)) {
|
---|
| 32 | Serial.print("Join AP success\r\n");
|
---|
| 33 | Serial.print("IP: ");
|
---|
| 34 | Serial.println(wifi.getLocalIP().c_str());
|
---|
| 35 | } else {
|
---|
| 36 | Serial.print("Join AP failure\r\n");
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | //Set single mode
|
---|
| 40 | if (wifi.disableMUX()) {
|
---|
| 41 | Serial.print("single ok\r\n");
|
---|
| 42 | } else {
|
---|
| 43 | Serial.print("single err\r\n");
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | //"on" API was able to call in setup
|
---|
| 47 | milkcocoa.on("milkcocoa_datastore_name", "push", onpush);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | void loop() {
|
---|
| 51 | //milkcocoa.loop must be called in loop()
|
---|
| 52 | milkcocoa.loop();
|
---|
| 53 |
|
---|
| 54 | //push
|
---|
| 55 | DataElement elem = DataElement();
|
---|
| 56 | elem.setValue("name", "Milk");
|
---|
| 57 | elem.setValue("age", 35);
|
---|
| 58 | milkcocoa.push("milkcocoa_datastore_name", elem);
|
---|
| 59 |
|
---|
| 60 | delay(10000);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | void onpush(DataElement elem) {
|
---|
| 64 | Serial.println(elem.getString("name"));
|
---|
| 65 | Serial.println(elem.getInt("age"));
|
---|
| 66 | // Output:
|
---|
| 67 | // Milk
|
---|
| 68 | // 35
|
---|
| 69 | };
|
---|
| 70 | ```
|
---|
| 71 |
|
---|
| 72 | ### Using API Key
|
---|
| 73 |
|
---|
| 74 | If you use Milkcocoa API Key Authantication, please use `createWithApiKey`.
|
---|
| 75 |
|
---|
| 76 | ```
|
---|
| 77 | Milkcocoa *milkcocoa = Milkcocoa::createWithApiKey(&client, "milkcocoa_app_id.mlkcca.com", 1883, "milkcocoa_app_id", "mqtt_client_id", "API_KEY", "API_SECRET");
|
---|
| 78 | ```
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | ## Examples
|
---|
| 82 |
|
---|
| 83 | - [Simple ESP8266 Example](https://github.com/milk-cocoa/Milkcocoa_Arduino_SDK/blob/master/examples/milkcocoa_esp8266/milkcocoa_esp8266.ino): simple test of `push()` and `on("push")`.
|
---|
| 84 | - [ESP8266 TOUT Example](https://github.com/milk-cocoa/Milkcocoa_Arduino_SDK/blob/master/examples/milkcocoa_esp8266_tout/milkcocoa_esp8266_tout.ino): get sensor data from TOUT of ESP8266
|
---|
| 85 | - [ESP8266 API Key Authantication Example](https://github.com/milk-cocoa/Milkcocoa_Arduino_SDK/blob/master/examples/milkcocoa_esp8266_apikey_auth/milkcocoa_esp8266_apikey_auth.ino): auth with Milkcocoa API Key
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | ## LICENSE
|
---|
| 89 |
|
---|
| 90 | MIT
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | Copyright (c) 2015 Technical Rockstars.
|
---|
| 95 | Copyright (C) 2015 Embedded and Real-Time Systems Laboratory
|
---|
| 96 | Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 97 |
|
---|
| 98 | - Milkcocoa.h
|
---|
| 99 | - Milkcocoa.cpp
|
---|
| 100 |
|
---|
| 101 | ### Using
|
---|
| 102 |
|
---|
| 103 | - https://github.com/adafruit/Adafruit_MQTT_Library
|
---|
| 104 | - https://github.com/interactive-matter/aJson
|
---|
| 105 |
|
---|