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.
Fork of PGO6_VoteController_template by
main.cpp
00001 #define APP_VERSION 0.6f 00002 #define MQTT_VERSION 3 00003 #define BROKER_NAME "broker.hivemq.com" 00004 #define BROKER_PORT 1883 00005 00006 #include "debounce_button.h" 00007 #include "EthernetInterface.h" 00008 #include "MQTTNetwork.h" 00009 #include "MQTTmbed.h" 00010 #include "MQTTClient.h" 00011 00012 char* topic; 00013 00014 /** 00015 TODO 00016 ---- 00017 - Check if the button has been pressed. If so, print the amount of clicks to a serial terminal. 00018 - Make an MQTT-service which: 00019 - starts up a network using EthernetInterface. Make sure the development board requests its address via DHCP. 00020 - makes a client and connects it to the broker using a client ID and credentials (username & password). 00021 - sends messages at the same topic as the smartphone app from PGO 2. Feel free to choose which Quality of Service 00022 you are going to use. Make a separate function which handles the sending procedure. Therefore, this function 00023 can be called each time we want to send a certain message. 00024 - When the button is pressed once, we send an upvote. When pressed twice, a downvote is sent. By pressing 4 times, 00025 the program disconnects from the broker and terminates. 00026 00027 Extra 00028 ----- 00029 - Subscribe to the topic on which the song data is published. Display this received message on the serial terminal. 00030 - Test this controller in the complete system of PGO 2. Use these controllers instead of the smartphones. 00031 00032 Tips & tricks 00033 ------------- 00034 - To generate an interrupt on the press of a button, use: 00035 InterruptIn button(USER_BUTTON); 00036 ... 00037 button.fall(callback(someFunction)); 00038 - Before implementing MQTT, test the multiclick feature first. 00039 - Have a look at the MQTT-library for Mbed and the HelloMQTT-example. 00040 - To have a uniform message sending procedure, use the following function usage: 00041 sendMessage(&client, topic, buf, qos, retained, duplicate) 00042 */ 00043 00044 int main(int argc, char* argv[]) 00045 { 00046 InterruptIn button(USER_BUTTON); 00047 button.fall(callback(&button1_onpressed_cb)); 00048 button1_busy = false; 00049 button1_enabled = true; 00050 button1_pressed = false; 00051 multiclick_state = 0; 00052 // status_led = 0; 00053 00054 while(1){ 00055 if(debounced_flag){ 00056 // printf("debounced \r\n"); 00057 // printf("clicks %d\r\n", multiclick_state); 00058 // printf("button_enabled %d\r\n", button1_enabled); 00059 // printf("button_busy %d\r\n", button1_busy); 00060 debounced_flag = false; 00061 00062 } 00063 // printf("button_enabled %d\r\n", button1_enabled); 00064 if(done_counting){ 00065 printf("counted %d \r\n", multiclick_state); 00066 // handle click amount here 00067 multiclick_state = 0; 00068 done_counting = false; 00069 } 00070 } 00071 00072 return 0; 00073 }
Generated on Wed Jul 13 2022 04:12:15 by
