WizFi310 with MQTT Implementation for WizWikiw7500
Dependencies: DHT MQTT WizFi310Interface_Legacynew mbed-src
Revision 0:8007c0060f5f, committed 2018-02-01
- Comitter:
- kandilidinesh
- Date:
- Thu Feb 01 09:08:42 2018 +0000
- Commit message:
- WizFi310 with MQTT Implementation
Changed in this revision
diff -r 000000000000 -r 8007c0060f5f DHT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT.lib Thu Feb 01 09:08:42 2018 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/bangbh/code/DHT/#df22ddf10d75
diff -r 000000000000 -r 8007c0060f5f MQTT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQTT.lib Thu Feb 01 09:08:42 2018 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/jamesabruce/code/MQTT/#d3feba7f242a
diff -r 000000000000 -r 8007c0060f5f WizFi310Interface_Legacynew.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WizFi310Interface_Legacynew.lib Thu Feb 01 09:08:42 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/kandilidinesh/code/WizFi310Interface_Legacynew/#90f222eee7f7
diff -r 000000000000 -r 8007c0060f5f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 01 09:08:42 2018 +0000 @@ -0,0 +1,90 @@ +#include "mbed.h" +#include "WizFi310Interface.h" +#include "DHT.h" +#include "MQTTClient.h" +#include "MQTTmbed.h" +#include "MQTTSocket.h" +#define ECHO_SERVER_PORT 7 +#define USE_DHCP 1 + +#define SECURE WizFi310::SEC_WPA2_MIXED +#define AP_SSID "cdi1"// Input SSID +#define AP_PASSWORD "cdilab17" // Input PW + +#if defined(TARGET_WIZwiki_W7500) +Serial pc(USBTX, USBRX); +WizFi310Interface wifi(D1, D0, D7, D6, D8, NC, 115200); +#endif + +int arrivedcount = 0; + + class MQTTWIZ: public MQTTSocket +{ +public: + MQTTWIZ() + { + wait(1); + this->createSocket(); + } +}; + +void messageArrived(MQTT::MessageData& md) +{ + MQTT::Message &message = md.message; + printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n", message.qos, message.retained, message.dup, message.id); + printf("Payload %.*s\n", message.payloadlen, (char*)message.payload); + ++arrivedcount; +} + +void baud(int baudrate) { + Serial s(USBTX, USBRX); + s.baud(baudrate); +} + +int main (void) +{ + baud(115200); + //Wifi Connection + wifi.init(); + printf("WizFi310 \r\n"); + wifi.connect(SECURE,AP_SSID, AP_PASSWORD,WizFi310::WM_STATION); + printf("IP Address is %s\r\n", wifi.getIPAddress()); + //MQTT Connection + printf("Wait a second...\r\n"); + char* topic = "wizfi/temp"; + MQTTWIZ ipstack = MQTTWIZ(); + MQTT::Client<MQTTWIZ, Countdown> client = MQTT::Client<MQTTWIZ, Countdown>(ipstack); + DHT sensor(D14, DHT11); + char* hostname = "172.16.73.4"; + int port = 1883; + int rc = ipstack.connect(hostname, port); + printf("Topic: %s\r\n",topic); + MQTTPacket_connectData data = MQTTPacket_connectData_initializer; + data.MQTTVersion = 3; + data.clientID.cstring = "dinesh12319237983712"; + rc = client.connect(data); + rc = client.subscribe(topic, MQTT::QOS1, messageArrived); + MQTT::Message message; + int error = 0; + char buf[100]="Hello World"; + float temp=0.0; + while (true) + { + error = sensor.readData(); + if (0 == error) + { + temp = sensor.ReadTemperature(CELCIUS); + } + + message.qos = MQTT::QOS0; + message.retained = false; + message.dup = false; + sprintf(buf, "%3.1f", temp); + message.payload = (void*)buf; + message.payloadlen = strlen(buf); + rc = client.publish("wizfi/temp", message); + printf("Temperature Published : %s\r\n",message.payload); + client.yield(60000); + } +} +
diff -r 000000000000 -r 8007c0060f5f mbed-src.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Thu Feb 01 09:08:42 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-src/#a11c0372f0ba