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:
Tue Jul 15 09:56:43 2014 +0000
Parent:
21:25b85cbbdd82
Child:
23:39cf9f03b076
Commit message:
The platform-dependent code was modified to implemented in ifdef.; The process of debug log output was changed to macro.;

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
C12832_lcd.lib Show diff for this revision Revisions of this file
PowerControl/EthernetPowerControl.cpp Show annotated file Show diff for this revision Revisions of this file
SNICInterface.lib Show annotated file Show diff for this revision Revisions of this file
app_board_io.cpp 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Tue Jul 15 09:56:43 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/chris/code/C12832/#7de323fa46fe
--- a/C12832_lcd.lib	Tue Jul 15 02:08:48 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://mbed.org/users/dreschpe/code/C12832_lcd/#c9afe58d786a
--- a/PowerControl/EthernetPowerControl.cpp	Tue Jul 15 02:08:48 2014 +0000
+++ b/PowerControl/EthernetPowerControl.cpp	Tue Jul 15 09:56:43 2014 +0000
@@ -1,3 +1,4 @@
+#if defined(TARGET_LPC1768)
 #include "EthernetPowerControl.h"
 
 static void write_PHY (unsigned int PhyReg, unsigned short Value) {
@@ -135,4 +136,5 @@
     regv = read_PHY(PHY_REG_EDCR);
     write_PHY(PHY_REG_BMCR, regv & ~(1 << PHY_REG_EDCR_ENABLE));
     regv = read_PHY(PHY_REG_EDCR);   
-}
\ No newline at end of file
+}
+#endif
--- a/SNICInterface.lib	Tue Jul 15 02:08:48 2014 +0000
+++ b/SNICInterface.lib	Tue Jul 15 09:56:43 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/murata/code/SNICInterface/#a1233ca02edf
+http://mbed.org/teams/murata/code/SNICInterface/#b6b10c22a121
--- a/app_board_io.cpp	Tue Jul 15 02:08:48 2014 +0000
+++ b/app_board_io.cpp	Tue Jul 15 09:56:43 2014 +0000
@@ -1,7 +1,7 @@
 #include "app_board_io.h"
-#include "C12832_lcd.h"
+#include "C12832.h"
 
-extern C12832_LCD lcd;
+extern C12832 lcd;
 
 extern "C" void lcd_printf( const char* fmt, ...  )
 {
--- a/main.cpp	Tue Jul 15 02:08:48 2014 +0000
+++ b/main.cpp	Tue Jul 15 09:56:43 2014 +0000
@@ -29,13 +29,18 @@
 
 #include "MMA7660.h"
 #include "LM75B.h"
-#include "C12832_lcd.h"
+#include "C12832.h"
 
+#if defined(TARGET_LPC1768)
 #include "PowerControl/EthernetPowerControl.h"
-
+C12832 lcd(p5, p7, p6, p8, p11);
 MMA7660 axl(p28, p27);
 LM75B tmp(p28, p27);
-C12832_LCD lcd;
+#elif defined(TARGET_LPC1549)
+C12832 lcd(D11, D13, D12, D7, D10);
+MMA7660 axl(SDA, SCL);
+LM75B tmp(SDA, SCL);
+#endif
 
 #include "logo.h"
 
@@ -45,15 +50,21 @@
 #define DEMO_AP_SECUTIRY_KEY_LEN      8
 
 /** Wi-Fi SNIC UART Interface*/
+#if defined(TARGET_LPC1768)
 C_SNIC_WifiInterface     mSNICwifi( p9, p10, NC, NC, p30 );
-Serial pc(USBTX, USBRX);
+Serial pc(USBTX, USBRX);    /* for DEBUG_PRINT */
+#elif defined(TARGET_LPC1549)
+C_SNIC_WifiInterface     mSNICwifi( D0, D1, NC, NC, D3 );
+Serial pc(P2_12, P2_11);    /* for DEBUG_PRINT */
+#endif
 
 int main() {
     
+#if defined(TARGET_LPC1768)
     PHY_PowerDown();
-    
+#endif
     pc.baud( 115200 );
-    printf("main\r\n");
+    DEBUG_PRINT("main\r\n");
     lcd_print_xively_logo();
     
     // Initialize Wi-Fi interface