【mbed OS5対応バージョン】データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリです。 https://mlkcca.com/

Dependents:   mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn

Committer:
jksoft
Date:
Mon Mar 26 04:49:20 2018 +0000
Revision:
13:61e0cc093180
Parent:
12:6eafbe763882
???????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:0a2f634d3324 1 #include "Milkcocoa.h"
jksoft 9:5c195c1036da 2 #include "OldTimer.h"
jksoft 0:0a2f634d3324 3
jksoft 6:1b5ec3a15d67 4 #if 0
jksoft 0:0a2f634d3324 5 extern RawSerial pc;
jksoft 0:0a2f634d3324 6
jksoft 0:0a2f634d3324 7 #define DBG(x) x
jksoft 0:0a2f634d3324 8 #else
jksoft 0:0a2f634d3324 9 #define DBG(x)
jksoft 0:0a2f634d3324 10 #endif
jksoft 0:0a2f634d3324 11
jksoft 0:0a2f634d3324 12 DataElement::DataElement() {
jksoft 0:0a2f634d3324 13 json_msg[0] = '\0';
jksoft 0:0a2f634d3324 14 strcpy(json_msg,"{\"params\":{");
jksoft 0:0a2f634d3324 15 }
jksoft 0:0a2f634d3324 16
jksoft 0:0a2f634d3324 17 DataElement::DataElement(char *json_string) {
jksoft 0:0a2f634d3324 18 json_msg[0] = '\0';
jksoft 0:0a2f634d3324 19 strcpy(json_msg,json_string);
jksoft 0:0a2f634d3324 20 }
jksoft 0:0a2f634d3324 21
jksoft 0:0a2f634d3324 22 void DataElement::setValue(const char *key, const char *v) {
jksoft 0:0a2f634d3324 23 char json_string[64];
jksoft 0:0a2f634d3324 24 if( json_msg[strlen(json_msg)-1] != '{' )
jksoft 0:0a2f634d3324 25 {
jksoft 0:0a2f634d3324 26 strcat(json_msg,",");
jksoft 0:0a2f634d3324 27 }
jksoft 0:0a2f634d3324 28 sprintf(json_string,"\"%s\":\"%s\"",key,v);
jksoft 0:0a2f634d3324 29 strcat(json_msg,json_string);
jksoft 0:0a2f634d3324 30 }
jksoft 0:0a2f634d3324 31
jksoft 0:0a2f634d3324 32 void DataElement::setValue(const char *key, int v) {
jksoft 0:0a2f634d3324 33 char json_string[64];
jksoft 0:0a2f634d3324 34 if( json_msg[strlen(json_msg)-1] != '{' )
jksoft 0:0a2f634d3324 35 {
jksoft 0:0a2f634d3324 36 strcat(json_msg,",");
jksoft 0:0a2f634d3324 37 }
jksoft 0:0a2f634d3324 38 sprintf(json_string,"\"%s\":\"%d\"",key,v);
jksoft 0:0a2f634d3324 39 strcat(json_msg,json_string);
jksoft 0:0a2f634d3324 40 }
jksoft 0:0a2f634d3324 41
jksoft 0:0a2f634d3324 42 void DataElement::setValue(const char *key, double v) {
jksoft 0:0a2f634d3324 43 char json_string[64];
jksoft 0:0a2f634d3324 44 if( json_msg[strlen(json_msg)-1] != '{' )
jksoft 0:0a2f634d3324 45 {
jksoft 0:0a2f634d3324 46 strcat(json_msg,",");
jksoft 0:0a2f634d3324 47 }
jksoft 0:0a2f634d3324 48 sprintf(json_string,"\"%s\":\"%f\"",key,v);
jksoft 0:0a2f634d3324 49 strcat(json_msg,json_string);
jksoft 0:0a2f634d3324 50 }
jksoft 0:0a2f634d3324 51
jksoft 0:0a2f634d3324 52 char *DataElement::getString(const char *key) {
jksoft 0:0a2f634d3324 53 static char _word[64];
jksoft 0:0a2f634d3324 54 char *p;
jksoft 0:0a2f634d3324 55 int i=0;
jksoft 0:0a2f634d3324 56
jksoft 0:0a2f634d3324 57 strcpy(_word , "\"\0");
jksoft 0:0a2f634d3324 58 strcat(_word , key );
jksoft 0:0a2f634d3324 59 strcat(_word , "\"" );
jksoft 0:0a2f634d3324 60
jksoft 0:0a2f634d3324 61 p = strstr( (char*)json_msg , _word ) + 2 + strlen(_word);
jksoft 0:0a2f634d3324 62
jksoft 0:0a2f634d3324 63 while( (p[i] != ',')&&(p[i] != '\n')&&(p[i] != '\"') )
jksoft 0:0a2f634d3324 64 {
jksoft 0:0a2f634d3324 65 _word[i] = p[i];
jksoft 0:0a2f634d3324 66 i++;
jksoft 0:0a2f634d3324 67 }
jksoft 0:0a2f634d3324 68 _word[i] = '\0';
jksoft 0:0a2f634d3324 69
jksoft 0:0a2f634d3324 70 return _word;
jksoft 0:0a2f634d3324 71 }
jksoft 0:0a2f634d3324 72
jksoft 0:0a2f634d3324 73 int DataElement::getInt(const char *key) {
jksoft 0:0a2f634d3324 74 return atoi(getString(key));
jksoft 0:0a2f634d3324 75 }
jksoft 0:0a2f634d3324 76
jksoft 0:0a2f634d3324 77 float DataElement::getFloat(const char *key) {
jksoft 0:0a2f634d3324 78 return atof(getString(key));
jksoft 0:0a2f634d3324 79 }
jksoft 0:0a2f634d3324 80
jksoft 0:0a2f634d3324 81 char *DataElement::toCharArray() {
jksoft 0:0a2f634d3324 82 if( json_msg[strlen(json_msg)-1] != '{' )
jksoft 0:0a2f634d3324 83 {
jksoft 0:0a2f634d3324 84 strcat(json_msg,"}");
jksoft 0:0a2f634d3324 85 }
jksoft 0:0a2f634d3324 86 strcat(json_msg,"}");
jksoft 0:0a2f634d3324 87
jksoft 0:0a2f634d3324 88 return(json_msg);
jksoft 0:0a2f634d3324 89 }
jksoft 0:0a2f634d3324 90
jksoft 12:6eafbe763882 91 Milkcocoa::Milkcocoa(NetworkInterface* nif){
jksoft 12:6eafbe763882 92 ipstack = new MQTTInterface(nif);
jksoft 12:6eafbe763882 93 client = new MClient(ipstack);
jksoft 12:6eafbe763882 94
jksoft 12:6eafbe763882 95 for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
jksoft 12:6eafbe763882 96 milkcocoaSubscribers[i] = NULL;
jksoft 12:6eafbe763882 97 }
jksoft 12:6eafbe763882 98 }
jksoft 12:6eafbe763882 99
jksoft 0:0a2f634d3324 100 Milkcocoa::Milkcocoa(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id){
jksoft 0:0a2f634d3324 101 ipstack = new MQTTInterface(nif);
jksoft 0:0a2f634d3324 102 client = new MClient(ipstack);
jksoft 0:0a2f634d3324 103 strcpy(servername,host);
jksoft 0:0a2f634d3324 104 portnum = port;
jksoft 5:dd68fa651637 105 strcpy(app_id,_app_id);
jksoft 0:0a2f634d3324 106 strcpy(_clientid,client_id);
jksoft 0:0a2f634d3324 107 strcpy(username,"sdammy");
jksoft 0:0a2f634d3324 108 strcpy(password,app_id);
jksoft 6:1b5ec3a15d67 109
jksoft 7:f1e123331cad 110 for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
jksoft 7:f1e123331cad 111 milkcocoaSubscribers[i] = NULL;
jksoft 7:f1e123331cad 112 }
jksoft 7:f1e123331cad 113
jksoft 6:1b5ec3a15d67 114 #ifdef __MILKCOCOA_THREAD
jksoft 0:0a2f634d3324 115 setLoopCycle(5000);
jksoft 0:0a2f634d3324 116
jksoft 1:8e4149b53a8a 117 cycleThread1.start(Milkcocoa::threadStarter1,this);
jksoft 1:8e4149b53a8a 118 cycleThread2.start(Milkcocoa::threadStarter2,this);
jksoft 6:1b5ec3a15d67 119 #endif
jksoft 0:0a2f634d3324 120 }
jksoft 0:0a2f634d3324 121
jksoft 0:0a2f634d3324 122 Milkcocoa::Milkcocoa(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *_session){
jksoft 0:0a2f634d3324 123 ipstack = new MQTTInterface(nif);
jksoft 0:0a2f634d3324 124 client = new MClient(ipstack);
jksoft 0:0a2f634d3324 125 strcpy(servername,host);
jksoft 0:0a2f634d3324 126 portnum = port;
jksoft 5:dd68fa651637 127 strcpy(app_id,_app_id);
jksoft 0:0a2f634d3324 128 strcpy(_clientid,client_id);
jksoft 0:0a2f634d3324 129 strcpy(username,_session);
jksoft 0:0a2f634d3324 130 strcpy(password,app_id);
jksoft 6:1b5ec3a15d67 131
jksoft 7:f1e123331cad 132 for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
jksoft 7:f1e123331cad 133 milkcocoaSubscribers[i] = NULL;
jksoft 7:f1e123331cad 134 }
jksoft 7:f1e123331cad 135
jksoft 6:1b5ec3a15d67 136 #ifdef __MILKCOCOA_THREAD
jksoft 0:0a2f634d3324 137 setLoopCycle(5000);
jksoft 0:0a2f634d3324 138
jksoft 1:8e4149b53a8a 139 cycleThread1.start(Milkcocoa::threadStarter1,this);
jksoft 1:8e4149b53a8a 140 cycleThread2.start(Milkcocoa::threadStarter2,this);
jksoft 6:1b5ec3a15d67 141 #endif
jksoft 0:0a2f634d3324 142 }
jksoft 0:0a2f634d3324 143
jksoft 0:0a2f634d3324 144 Milkcocoa* Milkcocoa::createWithApiKey(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *key, char *secret) {
jksoft 0:0a2f634d3324 145 char session[60];
jksoft 0:0a2f634d3324 146 sprintf(session, "k%s:%s", key, secret);
jksoft 0:0a2f634d3324 147 return new Milkcocoa(nif, host, port, _app_id, client_id, session);
jksoft 0:0a2f634d3324 148 }
jksoft 0:0a2f634d3324 149
jksoft 12:6eafbe763882 150 void Milkcocoa::set_network_settinng(const char *host, uint16_t port, const char *_app_id, const char *client_id){
jksoft 12:6eafbe763882 151 strcpy(servername,host);
jksoft 12:6eafbe763882 152 portnum = port;
jksoft 12:6eafbe763882 153 strcpy(app_id,_app_id);
jksoft 12:6eafbe763882 154 strcpy(_clientid,client_id);
jksoft 12:6eafbe763882 155 strcpy(username,"sdammy");
jksoft 12:6eafbe763882 156 strcpy(password,app_id);
jksoft 12:6eafbe763882 157 }
jksoft 12:6eafbe763882 158
jksoft 0:0a2f634d3324 159 void Milkcocoa::connect() {
jksoft 0:0a2f634d3324 160
jksoft 0:0a2f634d3324 161 if(client->isConnected())
jksoft 0:0a2f634d3324 162 return;
jksoft 0:0a2f634d3324 163
jksoft 0:0a2f634d3324 164 if(client->connect(servername, portnum)!=0) {
jksoft 0:0a2f634d3324 165 DBG(pc.printf("Network connect err\r\n");)
jksoft 0:0a2f634d3324 166 return;
jksoft 0:0a2f634d3324 167 }
jksoft 9:5c195c1036da 168
jksoft 0:0a2f634d3324 169 MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
jksoft 0:0a2f634d3324 170 data.keepAliveInterval = 20;
jksoft 0:0a2f634d3324 171 data.cleansession = 1;
jksoft 0:0a2f634d3324 172 data.MQTTVersion = 4;
jksoft 0:0a2f634d3324 173 data.clientID.cstring = _clientid;
jksoft 0:0a2f634d3324 174 data.username.cstring = username;
jksoft 0:0a2f634d3324 175 data.password.cstring = password;
jksoft 0:0a2f634d3324 176
jksoft 0:0a2f634d3324 177 if (client->connect(data) != 0) {
jksoft 0:0a2f634d3324 178 DBG(pc.printf("Milkcocoa connect err\r\n");)
jksoft 0:0a2f634d3324 179 return;
jksoft 0:0a2f634d3324 180 }
jksoft 0:0a2f634d3324 181
jksoft 0:0a2f634d3324 182 }
jksoft 0:0a2f634d3324 183
jksoft 0:0a2f634d3324 184 bool Milkcocoa::push(const char *path, DataElement dataelement) {
jksoft 0:0a2f634d3324 185 milkcocoa_message_t *message = message_box.alloc();
jksoft 0:0a2f634d3324 186 char *buf;
jksoft 0:0a2f634d3324 187
jksoft 0:0a2f634d3324 188 if(message == NULL) return false;
jksoft 0:0a2f634d3324 189
jksoft 0:0a2f634d3324 190 sprintf(message->topic, "%s/%s/push", app_id, path);
jksoft 0:0a2f634d3324 191 buf = dataelement.toCharArray();
jksoft 0:0a2f634d3324 192 strcpy(message->message , buf);
jksoft 0:0a2f634d3324 193
jksoft 0:0a2f634d3324 194 osStatus stat = message_box.put(message);
jksoft 0:0a2f634d3324 195
jksoft 0:0a2f634d3324 196 if( stat != osOK ) return false;
jksoft 0:0a2f634d3324 197
jksoft 0:0a2f634d3324 198 return true;
jksoft 0:0a2f634d3324 199 }
jksoft 0:0a2f634d3324 200
jksoft 3:cddf81a87de3 201 bool Milkcocoa::push(const char *path, char *data) {
jksoft 6:1b5ec3a15d67 202
jksoft 3:cddf81a87de3 203 milkcocoa_message_t *message = message_box.alloc();
jksoft 3:cddf81a87de3 204 char *buf;
jksoft 3:cddf81a87de3 205
jksoft 3:cddf81a87de3 206 if(message == NULL) return false;
jksoft 3:cddf81a87de3 207
jksoft 3:cddf81a87de3 208 sprintf(message->topic, "%s/%s/push", app_id, path);
jksoft 3:cddf81a87de3 209
jksoft 4:9cfd43d8de16 210 strcpy(message->message , "{\"params\":");
jksoft 3:cddf81a87de3 211 strcat(message->message , data);
jksoft 3:cddf81a87de3 212 strcat(message->message , "}");
jksoft 3:cddf81a87de3 213
jksoft 3:cddf81a87de3 214 osStatus stat = message_box.put(message);
jksoft 3:cddf81a87de3 215
jksoft 3:cddf81a87de3 216 if( stat != osOK ) return false;
jksoft 3:cddf81a87de3 217
jksoft 3:cddf81a87de3 218 return true;
jksoft 3:cddf81a87de3 219 }
jksoft 3:cddf81a87de3 220
jksoft 0:0a2f634d3324 221 bool Milkcocoa::send(const char *path, DataElement dataelement) {
jksoft 0:0a2f634d3324 222 milkcocoa_message_t *message = message_box.alloc();
jksoft 0:0a2f634d3324 223 char *buf;
jksoft 0:0a2f634d3324 224
jksoft 0:0a2f634d3324 225 if(message == NULL) return false;
jksoft 0:0a2f634d3324 226
jksoft 0:0a2f634d3324 227 sprintf(message->topic, "%s/%s/send", app_id, path);
jksoft 0:0a2f634d3324 228 buf = dataelement.toCharArray();
jksoft 0:0a2f634d3324 229 strcpy(message->message , buf);
jksoft 0:0a2f634d3324 230
jksoft 0:0a2f634d3324 231 osStatus stat = message_box.put(message);
jksoft 0:0a2f634d3324 232
jksoft 0:0a2f634d3324 233 if( stat != osOK ) return false;
jksoft 6:1b5ec3a15d67 234
jksoft 0:0a2f634d3324 235 return true;
jksoft 0:0a2f634d3324 236 }
jksoft 0:0a2f634d3324 237
jksoft 3:cddf81a87de3 238 bool Milkcocoa::send(const char *path, char *data) {
jksoft 3:cddf81a87de3 239 milkcocoa_message_t *message = message_box.alloc();
jksoft 3:cddf81a87de3 240 char *buf;
jksoft 3:cddf81a87de3 241
jksoft 3:cddf81a87de3 242 if(message == NULL) return false;
jksoft 3:cddf81a87de3 243
jksoft 3:cddf81a87de3 244 sprintf(message->topic, "%s/%s/send", app_id, path);
jksoft 3:cddf81a87de3 245
jksoft 4:9cfd43d8de16 246 strcpy(message->message , "{\"params\":");
jksoft 3:cddf81a87de3 247 strcat(message->message , data);
jksoft 3:cddf81a87de3 248 strcat(message->message , "}");
jksoft 3:cddf81a87de3 249
jksoft 3:cddf81a87de3 250 osStatus stat = message_box.put(message);
jksoft 3:cddf81a87de3 251
jksoft 3:cddf81a87de3 252 if( stat != osOK ) return false;
jksoft 6:1b5ec3a15d67 253
jksoft 3:cddf81a87de3 254 return true;
jksoft 3:cddf81a87de3 255 }
jksoft 3:cddf81a87de3 256
jksoft 0:0a2f634d3324 257 void Milkcocoa::loop() {
jksoft 0:0a2f634d3324 258 connect();
jksoft 12:6eafbe763882 259 #ifndef __MILKCOCOA_THREAD
jksoft 12:6eafbe763882 260 send_massage();
jksoft 12:6eafbe763882 261 #endif
jksoft 6:1b5ec3a15d67 262 client->yield(1);
jksoft 12:6eafbe763882 263 }
jksoft 6:1b5ec3a15d67 264
jksoft 12:6eafbe763882 265 void Milkcocoa::send_massage(){
jksoft 12:6eafbe763882 266 while(1){
jksoft 12:6eafbe763882 267 osEvent evt = message_box.get(0);
jksoft 12:6eafbe763882 268 if (evt.status == osEventMail) {
jksoft 12:6eafbe763882 269 milkcocoa_message_t *message = (milkcocoa_message_t*)evt.value.p;
jksoft 12:6eafbe763882 270 MQTT::Message mq_message;
jksoft 12:6eafbe763882 271 if(message != NULL) {
jksoft 12:6eafbe763882 272 mq_message.qos = MQTT::QOS0;
jksoft 12:6eafbe763882 273 mq_message.retained = 0;
jksoft 12:6eafbe763882 274 mq_message.dup = false;
jksoft 12:6eafbe763882 275 mq_message.payload = (void*)message->message;
jksoft 12:6eafbe763882 276 mq_message.payloadlen = strlen(message->message);
jksoft 12:6eafbe763882 277 printf("milkcocoa send\r\n");
jksoft 12:6eafbe763882 278 client->publish(message->topic, mq_message);
jksoft 12:6eafbe763882 279
jksoft 12:6eafbe763882 280 message_box.free(message);
jksoft 12:6eafbe763882 281 }
jksoft 12:6eafbe763882 282 }
jksoft 12:6eafbe763882 283 else{
jksoft 12:6eafbe763882 284 break;
jksoft 6:1b5ec3a15d67 285 }
jksoft 6:1b5ec3a15d67 286 }
jksoft 0:0a2f634d3324 287 }
jksoft 0:0a2f634d3324 288
jksoft 0:0a2f634d3324 289 bool Milkcocoa::on(const char *path, const char *event, GeneralFunction cb) {
jksoft 0:0a2f634d3324 290 MilkcocoaSubscriber *sub = new MilkcocoaSubscriber(cb);
jksoft 0:0a2f634d3324 291 sprintf(sub->topic, "%s/%s/%s", app_id, path, event);
jksoft 0:0a2f634d3324 292
jksoft 0:0a2f634d3324 293 if (client->subscribe(sub->topic, MQTT::QOS0, cb) != 0) {
jksoft 0:0a2f634d3324 294 DBG(pc.printf("Milkcocoa subscribe err\r\n");)
jksoft 0:0a2f634d3324 295 return false;
jksoft 0:0a2f634d3324 296 }
jksoft 0:0a2f634d3324 297 for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
jksoft 0:0a2f634d3324 298 if (milkcocoaSubscribers[i] == sub) {
jksoft 0:0a2f634d3324 299 return false;
jksoft 0:0a2f634d3324 300 }
jksoft 0:0a2f634d3324 301 }
jksoft 0:0a2f634d3324 302 for (int i=0; i<MILKCOCOA_SUBSCRIBERS; i++) {
jksoft 0:0a2f634d3324 303 if (milkcocoaSubscribers[i] == 0) {
jksoft 0:0a2f634d3324 304 milkcocoaSubscribers[i] = sub;
jksoft 0:0a2f634d3324 305 return true;
jksoft 0:0a2f634d3324 306 }
jksoft 0:0a2f634d3324 307 }
jksoft 0:0a2f634d3324 308 return true;
jksoft 0:0a2f634d3324 309 }
jksoft 0:0a2f634d3324 310
jksoft 6:1b5ec3a15d67 311 #ifdef __MILKCOCOA_THREAD
jksoft 0:0a2f634d3324 312 void Milkcocoa::setLoopCycle(int cycle) {
jksoft 0:0a2f634d3324 313 loop_cycle = cycle;
jksoft 0:0a2f634d3324 314 }
jksoft 0:0a2f634d3324 315 void Milkcocoa::start() {
jksoft 1:8e4149b53a8a 316 cycleThread1.signal_set(START_THREAD);
jksoft 1:8e4149b53a8a 317 cycleThread2.signal_set(START_THREAD);
jksoft 0:0a2f634d3324 318 }
jksoft 0:0a2f634d3324 319
jksoft 1:8e4149b53a8a 320 void Milkcocoa::cycle_Thread1(void) {
jksoft 1:8e4149b53a8a 321 cycleThread1.signal_wait(START_THREAD);
jksoft 0:0a2f634d3324 322 while(1) {
jksoft 9:5c195c1036da 323 OldTimer timer;
jksoft 0:0a2f634d3324 324 timer.start();
jksoft 0:0a2f634d3324 325 connect();
jksoft 1:8e4149b53a8a 326
jksoft 1:8e4149b53a8a 327 client->yield(RECV_TIMEOUT);
jksoft 0:0a2f634d3324 328
jksoft 1:8e4149b53a8a 329 int sub_time = loop_cycle - timer.read();
jksoft 1:8e4149b53a8a 330 if( sub_time > 0 ){
jksoft 1:8e4149b53a8a 331 Thread::wait(sub_time);
jksoft 1:8e4149b53a8a 332 }
jksoft 1:8e4149b53a8a 333 timer.stop();
jksoft 1:8e4149b53a8a 334 }
jksoft 1:8e4149b53a8a 335 }
jksoft 1:8e4149b53a8a 336 void Milkcocoa::cycle_Thread2(void) {
jksoft 1:8e4149b53a8a 337 cycleThread2.signal_wait(START_THREAD);
jksoft 1:8e4149b53a8a 338 while(1) {
jksoft 1:8e4149b53a8a 339
jksoft 0:0a2f634d3324 340 osEvent evt = message_box.get();
jksoft 0:0a2f634d3324 341 if (evt.status == osEventMail) {
jksoft 0:0a2f634d3324 342 milkcocoa_message_t *message = (milkcocoa_message_t*)evt.value.p;
jksoft 0:0a2f634d3324 343 MQTT::Message mq_message;
jksoft 0:0a2f634d3324 344
jksoft 0:0a2f634d3324 345 if(message == NULL) break;
jksoft 0:0a2f634d3324 346
jksoft 0:0a2f634d3324 347 mq_message.qos = MQTT::QOS0;
jksoft 0:0a2f634d3324 348 mq_message.retained = 0;
jksoft 0:0a2f634d3324 349 mq_message.dup = false;
jksoft 0:0a2f634d3324 350 mq_message.payload = (void*)message->message;
jksoft 0:0a2f634d3324 351 mq_message.payloadlen = strlen(message->message);
jksoft 0:0a2f634d3324 352
jksoft 0:0a2f634d3324 353 client->publish(message->topic, mq_message);
jksoft 0:0a2f634d3324 354
jksoft 0:0a2f634d3324 355 message_box.free(message);
jksoft 1:8e4149b53a8a 356 }
jksoft 1:8e4149b53a8a 357 Thread::wait(1000);
jksoft 0:0a2f634d3324 358 }
jksoft 0:0a2f634d3324 359 }
jksoft 0:0a2f634d3324 360
jksoft 1:8e4149b53a8a 361 void Milkcocoa::threadStarter1(void const *p) {
jksoft 0:0a2f634d3324 362 Milkcocoa *instance = (Milkcocoa*)p;
jksoft 1:8e4149b53a8a 363 instance->cycle_Thread1();
jksoft 1:8e4149b53a8a 364 }
jksoft 1:8e4149b53a8a 365 void Milkcocoa::threadStarter2(void const *p) {
jksoft 1:8e4149b53a8a 366 Milkcocoa *instance = (Milkcocoa*)p;
jksoft 1:8e4149b53a8a 367 instance->cycle_Thread2();
jksoft 0:0a2f634d3324 368 }
jksoft 6:1b5ec3a15d67 369 #endif
jksoft 0:0a2f634d3324 370
jksoft 0:0a2f634d3324 371 MilkcocoaSubscriber::MilkcocoaSubscriber(GeneralFunction _cb) {
jksoft 0:0a2f634d3324 372 cb = _cb;
jksoft 0:0a2f634d3324 373 }
jksoft 0:0a2f634d3324 374