Port to C027 (using AppShield and Cellular)
Dependencies: C027_Support C12832 LM75B MMA7660 MQTT mbed-rtos mbed
Dependents: TCU-POC_BACK_WORKING
Fork of IBMIoTClientEthernetExample by
Revision 17:b08722ede282, committed 2015-07-03
- Comitter:
- mazgch
- Date:
- Fri Jul 03 11:46:09 2015 +0000
- Parent:
- 16:a931c0a6d987
- Commit message:
- added some additional modem sensor data
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r a931c0a6d987 -r b08722ede282 main.cpp --- a/main.cpp Thu Jul 02 12:54:15 2015 +0000 +++ b/main.cpp Fri Jul 03 11:46:09 2015 +0000 @@ -327,6 +327,37 @@ return client->publish(pubTopic, message); } +int publishMdm(MQTT::Client<MQTT_CLIENT_TYPE, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTT_CLIENT_TYPE* ipstack, MDMParser* mdm) +{ + MQTT::Message message; + char* pubTopic = "iot-2/evt/modem/fmt/json"; + char buf[250]; + int l = 0; + MDMParser::IP ip = mdm->getIpAddress(); + l += sprintf(buf+l,"{\"d\":{\"ip\":\"" IPSTR "\"", IPNUM(ip)); + MDMParser::NetStatus sta; + mdm->checkNetStatus(&sta); + //const char* txtAct[] = { "Unknown", "GSM", "Edge", "3G", "CDMA" }; + //if (sta.act < sizeof(txtAct)/sizeof(*txtAct) && (sta.act != MDMParser::ACT_UNKNOWN)) + // l += sprintf(buf+l,",\"act\":\"%s\"",txtAct[sta.act]); + //if (*sta.num) l += sprintf(buf+l,",\"num\":\"%s\"",sta.num); + //if (sta.lac != 0xFFFF) l += sprintf(buf+l,",\"lac\":\"%04X\"",sta.lac); + //if (sta.ci != 0xFFFFFFFF) l += sprintf(buf+l,",\"ci\":\"%06X\"",sta.ci); + if (sta.rssi) l += sprintf(buf+l,",\"rssi\":%d",sta.rssi); + if (sta.ber) l += sprintf(buf+l,",\"ber\":%d",sta.ber); + if (*sta.opr) l += sprintf(buf+l,",\"operator\":\"%s\"",sta.opr); + l += sprintf(buf+l,"}}"); + + message.qos = MQTT::QOS0; + message.retained = false; + message.dup = false; + message.payload = (void*)buf; + message.payloadlen = strlen(buf); + + LOG("Publishing %s\n", buf); + return client->publish(pubTopic, message); +} + int publishGps(MQTT::Client<MQTT_CLIENT_TYPE, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTT_CLIENT_TYPE* ipstack, double lat, double lon) { MQTT::Message message; @@ -392,7 +423,7 @@ #endif MDMSerial mdm; - //mdm.setDebug(4); // enable this for debugging issues + //mdm.setDebug(3); // enable this for debugging issues if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD)) return -1; @@ -426,7 +457,8 @@ { if (++count == 100) { // Publish a message every second - if (publish(&client, &ipstack) != 0) + if ((publish(&client, &ipstack) != 0) || + (publishMdm(&client, &ipstack, &mdm) != 0)) attemptConnect(&client, &ipstack); // if we have lost the connection count = 0; }