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

Files at this revision

API Documentation at this revision

Comitter:
MACRUM
Date:
Sun Mar 22 14:13:25 2015 +0000
Parent:
14:1dd53a6d02d2
Child:
16:c57dac84da92
Commit message:
Initial commit

Changed in this revision

EthernetInterface.lib Show diff for this revision Revisions of this file
LPC1768.h Show annotated file Show diff for this revision Revisions of this file
MQTT.lib Show annotated file Show diff for this revision Revisions of this file
PowerControl.lib Show annotated file Show diff for this revision Revisions of this file
SNICInterface_mod.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/EthernetInterface.lib	Sun Mar 22 03:12:30 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
--- a/LPC1768.h	Sun Mar 22 03:12:30 2015 +0000
+++ b/LPC1768.h	Sun Mar 22 14:13:25 2015 +0000
@@ -63,11 +63,10 @@
 
 #define DEFAULT_TYPE_NAME "iotsample-mbed-lpc1768"
 
-#include "lpc_phy.h"
 // need a wrapper since K64F and LPC1768 wont have the same name for mii read methods
 static uint32_t linkStatus(void)
 {
-    return (lpc_mii_read_data() & 1);
+    return 1;
 }
 
 #endif
\ No newline at end of file
--- a/MQTT.lib	Sun Mar 22 03:12:30 2015 +0000
+++ b/MQTT.lib	Sun Mar 22 14:13:25 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/mqtt/code/MQTT/#c299463ae853
+http://mbed.org/teams/mqtt/code/MQTT/#8c534502ab7e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PowerControl.lib	Sun Mar 22 14:13:25 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JST2011/code/PowerControl/#d0fa2aeb02a4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SNICInterface_mod.lib	Sun Mar 22 14:13:25 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/KDDI-Fx0-hackathon/code/SNICInterface_mod/#d390d41d1405
--- 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