nc
Dependencies: mbed-src WizFi310Interface_Legacy_ DHT MQTT
Revision 18:0596e033d027, committed 2019-01-10
- Comitter:
- irayya
- Date:
- Thu Jan 10 05:36:23 2019 +0000
- Parent:
- 17:778cf2eacb1e
- Commit message:
- MQTT protocol tested using wiz310 wifi shield
Changed in this revision
WizFi310Interface_Legacynew.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/WizFi310Interface_Legacynew.lib Tue Jan 09 04:09:48 2018 +0000 +++ b/WizFi310Interface_Legacynew.lib Thu Jan 10 05:36:23 2019 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/akshaytom/code/WizFi310Interface_Legacynew/#aba7465a254d +https://os.mbed.com/users/irayya/code/WizFi310Interface_Legacy_/#a834975dbfff
--- a/main.cpp Tue Jan 09 04:09:48 2018 +0000 +++ b/main.cpp Thu Jan 10 05:36:23 2019 +0000 @@ -1,13 +1,18 @@ + + #include "mbed.h" #include "WizFi310Interface.h" #include "DHT.h" #include "MQTTClient.h" #include "MQTTmbed.h" #include "MQTTSocket.h" - +#include "string.h" #define SECURE WizFi310::SEC_WPA2_MIXED -#define SSID "CDI" -#define PASS "Cdi*1717" +#define SSID "CDI_STAFF" +#define PASS "uDQmAfJY" // should use perticular passd for each wizfi-310 device with CDI_STAFF network +DigitalOut led1(D0); +char msg[16]; +char result[10]; /* SET DHCP */ @@ -22,12 +27,27 @@ int arrivedcount = 0; void messageArrived(MQTT::MessageData& md) { + MQTT::Message &message = md.message; + + sprintf(result, "%.*s", message.payloadlen,(char*)message.payload); + if(strcmp(result,"on") == 0) + { + led1 = 1; + printf("LED blink \n"); + } + if(strcmp(result,"off")== 0) + { + led1 = 0; + printf("buzz\n"); + } + memset(result,'\0', sizeof(result)); 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; } + class MQTTWIZ: public MQTTSocket { public: @@ -43,7 +63,7 @@ pc.baud(115200); - + char* topicfan = "/led"; printf("WizFi310 STATION. \r\n"); wizfi310.init(); printf("After Initialisation. \r\n"); @@ -67,16 +87,22 @@ char MQTTClientID[30]; - MQTTPacket_connectData data = MQTTPacket_connectData_initializer; - data.MQTTVersion = 3; - sprintf(MQTTClientID,"WIZwiki-W7500-client-%d",rand()%1000); - data.clientID.cstring = MQTTClientID; - data.username.cstring = "testuser"; - data.password.cstring = "testpassword"; + //MQTTPacket_connectData data = MQTTPacket_connectData_initializer; +// data.MQTTVersion = 3; +// sprintf(MQTTClientID,"WIZwiki-W7500-client-%d",rand()%1000); +// data.clientID.cstring = MQTTClientID; +// data.username.cstring = "testuser"; +// data.password.cstring = "testpassword"; + MQTTPacket_connectData data = MQTTPacket_connectData_initializer; + data.MQTTVersion = 3; + data.clientID.cstring = "parents"; if ((rc = client.connect(data)) != 0) printf("rc from MQTT connect is %d\n", rc); + if ((rc = client.subscribe(topicfan, MQTT::QOS1, messageArrived)) == 0) + printf("rc from MQTT subscribe for fan is %d\n", rc); + MQTT::Message message; char buf[100]; int error = 0;