【mbed OS5対応バージョン】データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリです。 https://mlkcca.com/
Dependents: mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn
Revision 3:cddf81a87de3, committed 2017-05-18
- Comitter:
- jksoft
- Date:
- Thu May 18 14:47:30 2017 +0000
- Parent:
- 1:8e4149b53a8a
- Child:
- 4:9cfd43d8de16
- Commit message:
- ???????????push?send???????
Changed in this revision
Milkcocoa.cpp | Show annotated file Show diff for this revision Revisions of this file |
Milkcocoa.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Milkcocoa.cpp Wed Feb 15 02:15:55 2017 +0000 +++ b/Milkcocoa.cpp Thu May 18 14:47:30 2017 +0000 @@ -165,6 +165,25 @@ return true; } +bool Milkcocoa::push(const char *path, char *data) { + milkcocoa_message_t *message = message_box.alloc(); + char *buf; + + if(message == NULL) return false; + + sprintf(message->topic, "%s/%s/push", app_id, path); + + strcpy(message->message , "{\"params\":{"); + strcat(message->message , data); + strcat(message->message , "}"); + + osStatus stat = message_box.put(message); + + if( stat != osOK ) return false; + + return true; +} + bool Milkcocoa::send(const char *path, DataElement dataelement) { milkcocoa_message_t *message = message_box.alloc(); char *buf; @@ -182,6 +201,25 @@ return true; } +bool Milkcocoa::send(const char *path, char *data) { + milkcocoa_message_t *message = message_box.alloc(); + char *buf; + + if(message == NULL) return false; + + sprintf(message->topic, "%s/%s/send", app_id, path); + + strcpy(message->message , "{\"params\":{"); + strcat(message->message , data); + strcat(message->message , "}"); + + osStatus stat = message_box.put(message); + + if( stat != osOK ) return false; + + return true; +} + void Milkcocoa::loop() { connect(); client->yield(RECV_TIMEOUT);
--- a/Milkcocoa.h Wed Feb 15 02:15:55 2017 +0000 +++ b/Milkcocoa.h Thu May 18 14:47:30 2017 +0000 @@ -45,7 +45,9 @@ void connect(); void loop(); bool push(const char *path, DataElement dataelement); + bool push(const char *path, char *data); bool send(const char *path, DataElement dataelement); + bool send(const char *path, char *data); bool on(const char *path, const char *event, GeneralFunction cb); void setLoopCycle(int cycle); void start();