![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Initial commit
Fork of PGO6_VoteController_template by
Diff: main.cpp
- Revision:
- 2:f283e5274a0f
- Parent:
- 1:e7a311bd038e
--- a/main.cpp Thu Oct 26 14:16:10 2017 +0000 +++ b/main.cpp Thu Oct 26 14:25:29 2017 +0000 @@ -47,6 +47,8 @@ - To have a uniform message sending procedure, use the following function usage: sendMessage(&client, topic, buf, qos, retained, duplicate) */ + +//Connects to Network & MQTT void connect(char* name){ interface.connect(); while(interface.get_ip_address()== NULL){ @@ -62,6 +64,7 @@ connected=1; } +//Publishes MQTT data void send(char* feedback){ char buf[100]; sprintf(buf, feedback); @@ -75,6 +78,7 @@ client.publish(TOPIC, message); } +//Disconnects MQTT void disconnect(void){ client.unsubscribe(TOPIC); client.disconnect(); @@ -82,10 +86,12 @@ connected=0; } +//Processes message arrived void messageArrived(MQTT::MessageData& md) { MQTT::Message &message = md.message; info=1; + //NOTE: Due to lack of working serial terminal, sends data to clubIOT/feedback for reading. This should be printf. char buf[100]; sprintf(buf,"Message arrived: qos %d, retained %d, dup %d, packetid %d\r\n", message.qos, message.retained, message.dup, message.id); send(buf); @@ -93,18 +99,20 @@ send(buf); } +//Subscribe to MQTT topic void subscribe(char* topic){ client.subscribe(topic, MQTT::QOS2, messageArrived); } + int main(int argc, char* argv[]) { - connect("Jef"); + connect("Reinout"); subscribe("clubIOT/songmeta"); + //Connect button to interrupt InterruptIn button(USER_BUTTON); + button.fall(callback(&button1_onpressed_cb)); - button.fall(callback(&button1_onpressed_cb)); - float x=0; while(connected){ if(!button1_busy && multiclick_state!=0){ if(multiclick_state==1)