【mbed OS5対応バージョン】データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリです。 https://mlkcca.com/
Dependents: mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn
Revision 1:8e4149b53a8a, committed 2017-02-15
- Comitter:
- jksoft
- Date:
- Wed Feb 15 02:15:55 2017 +0000
- Parent:
- 0:0a2f634d3324
- Child:
- 2:63228ec79756
- Child:
- 3:cddf81a87de3
- Commit message:
- Milkcocoa?????????????????????????; (?????????????????????????????????); MQTT?????????? 100->256
Changed in this revision
--- a/MQTT/MQTTAsync.h Thu Feb 09 07:26:57 2017 +0000 +++ b/MQTT/MQTTAsync.h Wed Feb 15 02:15:55 2017 +0000 @@ -62,7 +62,7 @@ limits() { - MAX_MQTT_PACKET_SIZE = 100; + MAX_MQTT_PACKET_SIZE = 256; MAX_MESSAGE_HANDLERS = 5; MAX_CONCURRENT_OPERATIONS = 1; // 1 indicates single-threaded mode - set to >1 for multithreaded mode command_timeout_ms = 30000;
--- a/MQTT/MQTTClient.h Thu Feb 09 07:26:57 2017 +0000 +++ b/MQTT/MQTTClient.h Wed Feb 15 02:15:55 2017 +0000 @@ -100,7 +100,7 @@ * @param Network a network class which supports send, receive * @param Timer a timer class with the methods: */ -template<class Network, class Timer, int MAX_MQTT_PACKET_SIZE = 100, int MAX_MESSAGE_HANDLERS = 5> +template<class Network, class Timer, int MAX_MQTT_PACKET_SIZE = 256, int MAX_MESSAGE_HANDLERS = 5> class Client {
--- a/Milkcocoa.cpp Thu Feb 09 07:26:57 2017 +0000 +++ b/Milkcocoa.cpp Wed Feb 15 02:15:55 2017 +0000 @@ -98,7 +98,8 @@ strcpy(password,app_id); setLoopCycle(5000); - cycleThread.start(Milkcocoa::threadStarter,this); + cycleThread1.start(Milkcocoa::threadStarter1,this); + cycleThread2.start(Milkcocoa::threadStarter2,this); } Milkcocoa::Milkcocoa(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *_session){ @@ -112,7 +113,8 @@ strcpy(password,app_id); setLoopCycle(5000); - cycleThread.start(Milkcocoa::threadStarter,this); + cycleThread1.start(Milkcocoa::threadStarter1,this); + cycleThread2.start(Milkcocoa::threadStarter2,this); } Milkcocoa* Milkcocoa::createWithApiKey(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *key, char *secret) { @@ -212,16 +214,30 @@ } void Milkcocoa::start() { - cycleThread.signal_set(START_THREAD); + cycleThread1.signal_set(START_THREAD); + cycleThread2.signal_set(START_THREAD); } -void Milkcocoa::cycle_Thread(void) { - cycleThread.signal_wait(START_THREAD); +void Milkcocoa::cycle_Thread1(void) { + cycleThread1.signal_wait(START_THREAD); while(1) { Timer timer; timer.start(); connect(); + + client->yield(RECV_TIMEOUT); + int sub_time = loop_cycle - timer.read(); + if( sub_time > 0 ){ + Thread::wait(sub_time); + } + timer.stop(); + } +} +void Milkcocoa::cycle_Thread2(void) { + cycleThread2.signal_wait(START_THREAD); + while(1) { + osEvent evt = message_box.get(); if (evt.status == osEventMail) { milkcocoa_message_t *message = (milkcocoa_message_t*)evt.value.p; @@ -238,19 +254,18 @@ client->publish(message->topic, mq_message); message_box.free(message); - } - - client->yield(RECV_TIMEOUT); - - timer.stop(); - - if( timer.read() < loop_cycle ) Thread::wait(loop_cycle - timer.read()); + } + Thread::wait(1000); } } -void Milkcocoa::threadStarter(void const *p) { +void Milkcocoa::threadStarter1(void const *p) { Milkcocoa *instance = (Milkcocoa*)p; - instance->cycle_Thread(); + instance->cycle_Thread1(); +} +void Milkcocoa::threadStarter2(void const *p) { + Milkcocoa *instance = (Milkcocoa*)p; + instance->cycle_Thread2(); } MilkcocoaSubscriber::MilkcocoaSubscriber(GeneralFunction _cb) {
--- a/Milkcocoa.h Thu Feb 09 07:26:57 2017 +0000 +++ b/Milkcocoa.h Wed Feb 15 02:15:55 2017 +0000 @@ -38,8 +38,7 @@ class Milkcocoa { public: - -// Milkcocoa(const char *host, uint16_t port, const char *_app_id, const char *client_id); + Milkcocoa(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id); Milkcocoa(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *_session); static Milkcocoa* createWithApiKey(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *key, char *secret); @@ -64,9 +63,12 @@ MClient *client; GeneralFunction _cb; MilkcocoaSubscriber *milkcocoaSubscribers[MILKCOCOA_SUBSCRIBERS]; - Thread cycleThread; - void cycle_Thread(void); - static void threadStarter(void const *p); + Thread cycleThread1; + Thread cycleThread2; + void cycle_Thread1(void); + void cycle_Thread2(void); + static void threadStarter1(void const *p); + static void threadStarter2(void const *p); typedef struct { char message[256];