iot_water_monitor_v2
Dependencies: easy-connect-v16 Watchdog FP MQTTPacket RecordType-v-16 watersenor_and_temp_code
Diff: Simple-MQTT/SimpleMQTT.h
- Revision:
- 57:898fcb6692cd
- Parent:
- 55:c405323f8d5a
--- a/Simple-MQTT/SimpleMQTT.h Fri Mar 30 10:55:27 2018 +0000 +++ b/Simple-MQTT/SimpleMQTT.h Tue Apr 03 17:03:01 2018 +0000 @@ -166,6 +166,7 @@ */ int MQTT_PublishAll(MQTT::Client<MQTTNetwork, Countdown, MQTT_MAX_PACKET_SIZE>* client, time_t inputTime, uint8_t uploadType, struct UploadValue uploadStruct); +int MQTT_PublishDeviceManage(MQTT::Client<MQTTNetwork, Countdown, MQTT_MAX_PACKET_SIZE>* client, time_t inputTime, uint32_t uploadPeriod, uint32_t sendTimePeriod); /********************************************************************************************************************************************************************************************/ /*************************************************************** * Unity function declarations @@ -524,4 +525,32 @@ return retVal; } +int MQTT_PublishDeviceManage(MQTT::Client<MQTTNetwork, Countdown, MQTT_MAX_PACKET_SIZE>* client, time_t inputTime, uint32_t uploadPeriod, uint32_t sendTimePeriod) { + MQTT::Message message; + const char* pubTopic = MQTT_MANAGE_TOPIC; + char buf[MQTT_MAX_PAYLOAD_SIZE]; + char timeBuf[50]; + + if (!client->isConnected()) { + printf ("---> MQTT DISCONNECTED\n\r"); + return MQTT::FAILURE; + } + strftime(timeBuf, 50, "%Y/%m/%d %H:%M:%S", localtime(&inputTime)); +// sprintf(buf, "{\"d\":{\"metadata\":{\"Device ID\":\"PROEVN\",\"Time\":%s,\"Upload Interval\":%d,\"Send Time Frame Interval\":%d},\"supports\":{\"deviceActions\":true}}}", +// timeBuf, uploadPeriod, sendTimePeriod); + sprintf(buf, "{\"d\":{\"metadata\":{\"Upload Interval\":%d},\"supports\":{\"deviceActions\":true}}}", + uploadPeriod); + message.qos = MQTT::QOS0; + message.retained = false; + message.dup = false; + message.payload = (void*)buf; + message.payloadlen = strlen(buf); + + if((message.payloadlen + strlen(pubTopic)+1) >= MQTT_MAX_PACKET_SIZE) + printf("message too long!\r\n"); + + LOG("Publishing %s\n\r", buf); + return client->publish(pubTopic, message); +} + #endif /* __SIMPLEMQTT_H__ */