IBM IoT Client WiFi example using Murata Type-YD WiFi module

Dependencies:   C12832_fix LM75B MMA7660 MQTT PowerControl SNICInterface mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by Toyomasa Watarai

/media/uploads/MACRUM/ibm_iotkit.jpg

Revision:
15:fa5357aa190a
Parent:
14:1dd53a6d02d2
Child:
16:c57dac84da92
--- a/main.cpp	Sun Mar 22 03:12:30 2015 +0000
+++ b/main.cpp	Sun Mar 22 14:13:25 2015 +0000
@@ -23,17 +23,21 @@
 
 #if defined(TARGET_LPC1768)
 // Comment out folloing line when you are not using Seeed Studio Arch Pro
-#define TARGET_ARCH_PRO
+//#define TARGET_ARCH_PRO
 #endif
 
 #include "LM75B.h"
 #include "MMA7660.h"
 #include "MQTTClient.h"
-#include "MQTTEthernet.h"
+#include "MQTTWifi.h"
 #include "C12832.h"
 #include "Arial12x12.h"
 #include "rtos.h"
 
+#if defined(TARGET_LPC1768)
+#include "EthernetPowerControl.h"
+#endif
+
 // Update this to the next number *before* a commit
 #define __APP_SW_REVISION__ "10"
 
@@ -74,7 +78,6 @@
 char* joystickPos = "CENTRE";
 int blink_interval = 0;
 
-
 void off()
 {
     r = g = b = 1.0;    // 1 is off, 0 is full brightness
@@ -200,7 +203,7 @@
 }
 
 
-int connect(MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTEthernet* ipstack)
+int connect(MQTT::Client<MQTTWifi, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTWifi* ipstack)
 {   
     const char* iot_ibm = ".messaging.internetofthings.ibmcloud.com";
     
@@ -245,7 +248,7 @@
 }
 
 
-void attemptConnect(MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTEthernet* ipstack)
+void attemptConnect(MQTT::Client<MQTTWifi, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTWifi* ipstack)
 {
     int retryAttempt = 0;
     connected = false;
@@ -282,7 +285,7 @@
 }
 
 
-int publish(MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTEthernet* ipstack)
+int publish(MQTT::Client<MQTTWifi, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTWifi* ipstack)
 {
     MQTT::Message message;
     char* pubTopic = "iot-2/evt/status/fmt/json";
@@ -325,13 +328,11 @@
     return rc;
 }
 #else
-char* getMac(EthernetInterface& eth, char* buf, int buflen)    // Obtain MAC address
-{   
-    strncpy(buf, eth.getMACAddress(), buflen);
-
-    char* pos;                                                 // Remove colons from mac address
-    while ((pos = strchr(buf, ':')) != NULL)
-        memmove(pos, pos + 1, strlen(pos) + 1);
+char* getMac(C_SNIC_WifiInterface& wifi, char* buf, int buflen)    // Obtain MAC address
+{
+    tagWIFI_STATUS_T stat;
+    wifi.getWifiStatus(&stat);
+    sprintf(buf, "%x%x%x%x%x%x\0", stat.mac_address[0],stat.mac_address[1],stat.mac_address[2],stat.mac_address[3],stat.mac_address[4],stat.mac_address[5]);
     return buf;
 }
 #endif
@@ -372,7 +373,11 @@
 
 
 int main()
-{    
+{
+#if defined(TARGET_LPC1768)
+    PHY_PowerDown();
+#endif
+
     quickstartMode = (strcmp(org, "quickstart") == 0);
 
     lcd.set_font((unsigned char*) Arial12x12);  // Set a nice font for the LCD screen
@@ -386,8 +391,8 @@
     Thread yellow_thread(flashing_yellow);  
 #endif
     
-    MQTTEthernet ipstack;
-    MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack);
+    MQTTWifi ipstack;
+    MQTT::Client<MQTTWifi, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack);
     
     if (quickstartMode)
     {
@@ -427,15 +432,3 @@
         client.yield(10);  // allow the MQTT client to receive messages
     }
 }
-
-#if defined(TARGET_ARCH_PRO) | defined(TARGET_RZ_A1H)
-extern "C" void mbed_mac_address(char *mac)
-{
-    mac[0] = 0x00;
-    mac[1] = 0x02;
-    mac[2] = 0xF7;
-    mac[3] = 0xF1;
-    mac[4] = 0x91;
-    mac[5] = 0x9F;
-};
-#endif