Ruben De Swaef
/
PGO6_VoteController_code
Votecontroller
Fork of PGO6_VoteController_template by
Diff: main.cpp
- Revision:
- 5:592f4272c549
- Parent:
- 4:bb892177ce23
--- a/main.cpp Mon Oct 15 14:54:25 2018 +0000 +++ b/main.cpp Mon Oct 15 15:58:17 2018 +0000 @@ -60,30 +60,42 @@ data.username.cstring = "user"; data.password.cstring = "pass"; client.connect(data); + connected = true; led2 = 1; + printf("connected\n"); } -void sendMessage(MQTT::Client<MQTTNetwork, Countdown>* client, char* topic, char* buf, int qos, bool retained, bool duplicate){ +void sendMessage(MQTT::Client<MQTTNetwork, Countdown>& client, char* topic, char* buf, int qos, bool retained, bool duplicate){ MQTT::Message message; - if(qos == 0){ - message.qos = MQTT::QOS0; + + switch(qos) + { + case 0: + message.qos = MQTT::QOS0; + break; + case 1: + message.qos = MQTT::QOS1; + break; + case 2: + message.qos = MQTT::QOS2; + break; + default: + message.qos = MQTT::QOS0; } + message.retained = retained; message.dup = duplicate; message.payload = (void*)buf; message.payloadlen = strlen(buf) + 1; - - client->publish(topic, message); + client.publish(topic, message); } int main(int argc, char* argv[]) { - printf("boot\n"); + printf("\nBoot controller \nConnecting... \n"); button.fall(callback(&button1_onpressed_cb)); - printf("here\n"); MQQTConnect(); - printf("connected\n"); while(connected){ if(!button1_busy && multiclick_state != 0){ char* buf = ""; @@ -91,20 +103,21 @@ { case 1: buf = "upvote"; - sendMessage(&client, topic, buf, 0, false, false); + sendMessage(client, topic, buf, 0, false, false); break; case 2: buf = "downvote"; - sendMessage(&client, topic, buf, 0, false, false); + sendMessage(client, topic, buf, 0, false, false); break; case 4: client.disconnect(); network.disconnect(); connected = false; led2 = 0; + break; } + printf("click %d: %s \n", multiclick_state, buf); multiclick_state = 0; - printf("\n click %d: %s", multiclick_state, buf); } } return 0;