Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
Diff: src/CloudDataHandler/CloudDataHandler.cpp
- Revision:
- 68:dbe39d83eb98
- Parent:
- 27:38205cebc3da
- Child:
- 77:43e0a3d9e536
--- a/src/CloudDataHandler/CloudDataHandler.cpp Thu Sep 15 21:45:29 2016 +0000 +++ b/src/CloudDataHandler/CloudDataHandler.cpp Fri Sep 16 21:16:22 2016 +0000 @@ -7,6 +7,8 @@ #include "rtos.h" #include "global.h" +bool CloudDataHandlerConnected = false; + void CloudDataHandler(void const *args) { int32_t ret; @@ -14,8 +16,34 @@ printf("\r%s has started...\n", __func__); while ( true ) { + + std::string tmp_buffer; + + CloudDataHandlerConnected = false; - std::string tmp_buffer("{\"mtype\":\"20\"}"); + if (!GLOBAL_mdot->getNetworkJoinStatus()) { + logInfo("network not joined, joining network"); + if ((ret = GLOBAL_mdot->joinNetwork()) != mDot::MDOT_OK) { + logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); + Thread::wait(30000); + continue; + } + } + + CloudDataHandlerConnected = true; + + osEvent evt = CloudDataHandlerMailBox.get(5000); + if (evt.status == osEventMail) { + CloudDataHandlerReq_t *mail = (CloudDataHandlerReq_t*)evt.value.p; + logInfo("Cloud Data Handler Mail Received: Entry: %s", mail->packet); + tmp_buffer = mail->packet; + CloudDataHandlerMailBox.free(mail); + break; + } else { + printf("Cloud Data Handler no MAIL\r\n"); + tmp_buffer = "{\"mtype\":\"20\"}"; + } + std::vector<uint8_t> data(tmp_buffer.begin(), tmp_buffer.end()); // send the data to the gateway @@ -32,7 +60,6 @@ CloudFileReceiver( &rcv_string, GLOBAL_mdot ); } } - Thread::wait(5000); } } } \ No newline at end of file