demo of Murata wifi chip as TCP client.

Dependencies:   SNICInterface mbed-rtos mbed

Fork of murataDemo by Austin Blackstone

Intro

this program demonstrates how to use TCP on the Murata Wifi chip. It will connect to a server and send a message, the server will then send a reply. The reply will be printed out to the terminal on the microcontroller.

Instructions

  1. Make sure you have both the wifi device and the computer running the server on the same network / wifi router.
  2. Change the hard coded IP in the microcontroller code to match that of the laptop running the python server.
  3. Run the python2 script below on the computer
  4. Have a console hooked up to the microcontroller and watch as messages are sent back and forth between the server (python) and the client (murata).
  5. Run the microcontroller code on the device.

For ease of use numbers have been appended to the end of the messages being sent back and forth.

Python Server

Please run this python2.7 code on your computer. Make sure to change the IP Address in the microcontroller code to match the IP of your computer.

import socket
 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 7))
s.listen(1)
 
x = 0
while True:
    conn, addr = s.accept()
    print 'Connected b'TCP data from server: 'y', addr
    while True:
        # receive data from board
        data = conn.recv(1024)
        
        # check received data
        if not data: 
            break
        
        # print received data 
        print("TCP data from microcontroller: '"+data+"'")
        
        # send data to board with counter to differentiate messages
        conn.sendall("HelloFromPython!: "+str(x)+"\n\r")
        x+=1

    # close the port
    conn.close()

Files at this revision

API Documentation at this revision

Comitter:
kishino
Date:
Mon May 26 06:28:29 2014 +0000
Parent:
13:d4a21765a203
Child:
15:abc12b228291
Commit message:
Created demo application for Xively using the SNIC with TypeYD.

Changed in this revision

EthernetInterface.lib Show diff for this revision Revisions of this file
SNICInterface.lib Show annotated file Show diff for this revision Revisions of this file
libxively.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Fri Nov 08 16:57:17 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#cba86db5ab96
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SNICInterface.lib	Mon May 26 06:28:29 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/murata/code/SNICInterface/#6a0ba999597d
--- a/libxively.lib	Fri Nov 08 16:57:17 2013 +0000
+++ b/libxively.lib	Mon May 26 06:28:29 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/xively/code/libxively/#4ce6299f7535
+http://mbed.org/users/xively/code/libxively/#1208875310d3
--- a/main.cpp	Fri Nov 08 16:57:17 2013 +0000
+++ b/main.cpp	Mon May 26 06:28:29 2014 +0000
@@ -1,8 +1,8 @@
 #include "mbed.h"
-#include "EthernetInterface.h"
+#include "SNIC_WifiInterface.h"
 
-#define XI_FEED_ID 128488 // set Xively Feed ID (numerical, no quoutes)
-#define XI_API_KEY "T4KXAH_dasgw1PWBPc3fdsfsdgsdy-dUc4ND0g" // set Xively API key (double-quoted string)
+#define XI_FEED_ID 1056160623 // set Xively Feed ID (numerical, no quoutes)
+#define XI_API_KEY "Wg7CfZDrj7VjIIpiYzdDrMow6wdENAOGjkIfQ0fUjJh6DAw2" // set Xively API key (double-quoted string)
 
 #include "app_board_io.h"
 
@@ -19,30 +19,61 @@
 
 #include "logo.h"
 
+#if 0
+#define DEMO_AP_SSID                    "HWD11_E8088BD5E3A8"
+#define DEMO_AP_SECURITY_TYPE           e_SEC_WPA2_AES
+#define DEMO_AP_SECUTIRY_KEY            "aArGrg303DG5HA9"
+#define DEMO_AP_SECUTIRY_KEY_LEN    15
+#else
+//#define DEMO_AP_SSID                          "muRata1"
+//#define DEMO_AP_SECURITY_TYPE         e_SEC_WPA2_AES
+//#define DEMO_AP_SECUTIRY_KEY          "12345678"
+//#define DEMO_AP_SECUTIRY_KEY_LEN  8
+
+#define DEMO_AP_SSID                    "Test"
+#define DEMO_AP_SECURITY_TYPE           e_SEC_WPA2_AES
+#define DEMO_AP_SECUTIRY_KEY            "eightspot"
+#define DEMO_AP_SECUTIRY_KEY_LEN    9
+#endif
+/** Wi-Fi SNIC UART Interface*/
+C_SNIC_WifiInterface     mSNICwifi( p9, p10, NC, NC, p30 );
+Serial pc(USBTX, USBRX);
+ 
 int main() {
+    pc.baud( 115200 );
+    printf("main\r\n");
     lcd_print_xively_logo();
-    EthernetInterface eth;
     
-    int s = eth.init(); //Use DHCP
+    // Initialize Wi-Fi interface
+    int s = mSNICwifi.init();
     
-    if( s != NULL )
+    lcd_printf("init();\r\n");
+    
+    if( s != 0 )
     {
         lcd_printf( "Could not initialise. Will halt!\n" );        
-        exit( 0 );
+        return -1;
     }    
         
-    s = eth.connect();
+    wait(0.5);
+    mSNICwifi.disconnect();
+    lcd_printf("disconnect();\r\n");
     
-    if( s != NULL )
+    wait(0.5);
+    // Connect AP
+    s = mSNICwifi.connect( DEMO_AP_SSID
+                        , strlen(DEMO_AP_SSID)
+                        , DEMO_AP_SECURITY_TYPE
+                        , DEMO_AP_SECUTIRY_KEY
+                        , DEMO_AP_SECUTIRY_KEY_LEN );
+    lcd_printf("connect();\r\n");
+    if( s != 0 )
     {
         lcd_printf( "Could not connect. Will halt!\n" );
-        exit( 0 );
+        return -1;
     }
-    else 
-    {
-        lcd_printf( "IP: %s\n", eth.getIPAddress() );    
-    }
-    
+    wait(0.5);
+
     xi_feed_t feed;
     memset( &feed, NULL, sizeof( xi_feed_t ) );
     
@@ -112,6 +143,6 @@
       xi_feed_update( xi_context, &feed );
       lcd_printf( "done...\n" );
       
-      wait( 15.0 );
+      wait( 1.0 );
     }
 }
--- a/mbed-rtos.lib	Fri Nov 08 16:57:17 2013 +0000
+++ b/mbed-rtos.lib	Mon May 26 06:28:29 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
+http://mbed.org/users/mbed_official/code/mbed-rtos/#5dfe422a963d
--- a/mbed.bld	Fri Nov 08 16:57:17 2013 +0000
+++ b/mbed.bld	Mon May 26 06:28:29 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file