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: EthernetInterface MQTT mbed-rtos mbed
Fork of HelloMQTT by
Revision 18:53d83febbe0a, committed 2015-03-16
- Comitter:
- stefan1691
- Date:
- Mon Mar 16 14:12:35 2015 +0000
- Parent:
- 17:719bb7709c80
- Commit message:
- Poti hinzugefuegt, JSON entfernt
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Mar 16 10:26:15 2015 +0000 +++ b/main.cpp Mon Mar 16 14:12:35 2015 +0000 @@ -1,10 +1,11 @@ -/** MQTT Publish von Sensordaten als JSON */ +/** MQTT Publish von Sensordaten */ #include "mbed.h" #include "MQTTEthernet.h" #include "MQTTClient.h" -// Topic -char* topic = "mbed/k64f/iotkit"; +// Topic's +char* topicLight = "mbed/k64f/iotkit/light"; +char* topicPoti = "mbed/k64f/iotkit/poti"; // MQTT Brocker char* hostname = "iot.eclipse.org"; int port = 1883; @@ -14,6 +15,8 @@ char buf[100]; // UI DigitalOut led1( LED1 ); +// Poti +AnalogIn poti( A0 ); // Lichtsensor AnalogIn light( A1 ); @@ -35,14 +38,24 @@ printf("rc from MQTT connect is %d\n", rc); // Message als JSON aufbereiten und senden - sprintf( buf, "{ \"light:\": %f }", light.read() ); + sprintf( buf, "%f", light.read() ); printf( "Publish: %s\n", buf ); message.qos = MQTT::QOS0; message.retained = false; message.dup = false; message.payload = (void*) buf; message.payloadlen = strlen(buf)+1; - client.publish(topic, message); + client.publish( topicLight, message); + + // Message als JSON aufbereiten und senden + sprintf( buf, "%f", poti.read() ); + printf( "Publish: %s\n", buf ); + message.qos = MQTT::QOS0; + message.retained = false; + message.dup = false; + message.payload = (void*) buf; + message.payloadlen = strlen(buf)+1; + client.publish( topicPoti, message); // Verbindung beenden, ansonsten ist nach 4x Schluss client.disconnect();