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: LCD_i2c_GSOE ESP8266MQTT
main.cpp
00001 #include "mbed.h" 00002 #include "PubSubClient.h" 00003 #include "LCD.h" 00004 /* 00005 "wifi-ssid": { 00006 "help": "WiFi SSID", 00007 "value": "\"x-Netz\"" 00008 }, 00009 "wifi-password": { 00010 "help": "WiFi Password", 00011 "value": "\"aCT3xuSbm9rt\"" 00012 }, 00013 */ 00014 /* 00015 "mqtt-broker-hostname": { 00016 "help": "MQTT Broker resolvable hostname.", 00017 "value": "\"test.mosquitto.org\"" 00018 }, 00019 */ 00020 PortOut diag(PortC,0xFF); 00021 AnalogIn poti(PA_0); 00022 lcd mylcd; 00023 00024 PubSubClient client; 00025 00026 /* 00027 struct Message 00028 { 00029 enum QoS qos; 00030 bool retained; 00031 bool dup; 00032 unsigned short id; 00033 void *payload; 00034 size_t payloadlen; 00035 }; 00036 00037 00038 struct MessageData 00039 { 00040 MessageData(MQTTString &aTopicName, struct Message &aMessage) : message(aMessage), topicName(aTopicName) 00041 { } 00042 00043 struct Message &message; 00044 MQTTString &topicName; 00045 }; 00046 */ 00047 00048 void subscribeCallback(MessageData& mymessage) 00049 { 00050 mylcd.cursorpos(0); 00051 mylcd.printf("%s ",client.gibPayload(mymessage).c_str()); 00052 } 00053 00054 void subscribeCallback2(MessageData& mymessage) 00055 { 00056 00057 mylcd.cursorpos(0x40); 00058 mylcd.printf("%s ",client.gibPayload(mymessage).c_str()); 00059 } 00060 00061 00062 //test.mosquitto.org 5.196.95.208 00063 int main() 00064 { 00065 diag=1; 00066 int d; 00067 char buffer[64]; 00068 mylcd.clear(); 00069 client.connect((char*)"joerg"); 00070 client.subscribe("MBED/joerg/ersteTests", QOS0, subscribeCallback); 00071 client.subscribe("MBED/joerg/zweiteTests", QOS0, subscribeCallback2); 00072 while(true) 00073 { 00074 client.loop(); 00075 diag=diag+1; 00076 d=diag; 00077 sprintf(buffer, "poti=%d", (int)(poti*4095)); 00078 client.publish("MBED/joerg/ersteTests", buffer); 00079 //HAL_Delay(200); 00080 sprintf(buffer, "diag=%d", d); 00081 client.publish("MBED/joerg/zweiteTests", buffer); 00082 //HAL_Delay(200); 00083 } 00084 } 00085 00086 00087 00088
Generated on Mon Aug 8 2022 13:14:52 by
1.7.2