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()

Committer:
errordeveloper
Date:
Mon Oct 14 13:33:04 2013 +0000
Revision:
11:bdf601a405fc
Child:
15:abc12b228291
Improve a few things about the LCD output:; ; * don't output debug logs; * show Xively logo on boot;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
errordeveloper 11:bdf601a405fc 1 static char xively_logo_data[] = {
errordeveloper 11:bdf601a405fc 2 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 3 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 4 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c, 0x0,
errordeveloper 11:bdf601a405fc 5 0x0, 0x0, 0x0, 0xe0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 6 0x3e, 0x0, 0x0, 0x0, 0x0, 0xf0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 7 0x0, 0x0, 0x3e, 0x0, 0x0, 0x0, 0x0, 0xf0,
errordeveloper 11:bdf601a405fc 8 0x0, 0x0, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 9 0x0, 0xf0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 10 0x0, 0x0, 0x0, 0xf0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 11 0x0, 0x0, 0x0, 0x0, 0x0, 0xf0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 12 0x10, 0x0, 0x0, 0x0, 0x0, 0xf, 0xc0, 0xf0,
errordeveloper 11:bdf601a405fc 13 0x0, 0x0, 0x1e, 0x7, 0x9c, 0xf0, 0x1e, 0x3f,
errordeveloper 11:bdf601a405fc 14 0xf0, 0xf7, 0x80, 0x78, 0xf, 0xf, 0x1c, 0xf0,
errordeveloper 11:bdf601a405fc 15 0x1e, 0x7f, 0xf8, 0xf7, 0x80, 0xf0, 0x7, 0x9e,
errordeveloper 11:bdf601a405fc 16 0x1c, 0xf0, 0x1e, 0xf8, 0x78, 0xf3, 0xc0, 0xf0,
errordeveloper 11:bdf601a405fc 17 0x7, 0x9e, 0x1c, 0x78, 0x3c, 0xf0, 0x3c, 0xf3,
errordeveloper 11:bdf601a405fc 18 0xc0, 0xe0, 0x3, 0xfc, 0x1c, 0x78, 0x3d, 0xe0,
errordeveloper 11:bdf601a405fc 19 0x1c, 0xf3, 0xc1, 0xe0, 0x1, 0xf8, 0x1c, 0x38,
errordeveloper 11:bdf601a405fc 20 0x39, 0xe0, 0x1c, 0xf1, 0xe1, 0xe0, 0x1, 0xf8,
errordeveloper 11:bdf601a405fc 21 0x1c, 0x3c, 0x79, 0xff, 0xfe, 0xf1, 0xe3, 0xc0,
errordeveloper 11:bdf601a405fc 22 0x1, 0xf8, 0x1c, 0x3c, 0x79, 0xff, 0xfe, 0xf0,
errordeveloper 11:bdf601a405fc 23 0xe3, 0xc0, 0x1, 0xf8, 0x1c, 0x1e, 0xf1, 0xe0,
errordeveloper 11:bdf601a405fc 24 0x0, 0xf0, 0xf3, 0x80, 0x3, 0xfc, 0x1c, 0x1e,
errordeveloper 11:bdf601a405fc 25 0xf1, 0xe0, 0x0, 0xf0, 0x77, 0x80, 0x7, 0x9e,
errordeveloper 11:bdf601a405fc 26 0x1c, 0xf, 0xe0, 0xf0, 0x0, 0xf0, 0x7f, 0x80,
errordeveloper 11:bdf601a405fc 27 0x7, 0x8f, 0x1c, 0xf, 0xe0, 0xf8, 0x10, 0xf0,
errordeveloper 11:bdf601a405fc 28 0x7f, 0x0, 0xf, 0xf, 0x1c, 0xf, 0xe0, 0x7f,
errordeveloper 11:bdf601a405fc 29 0xf8, 0xf0, 0x3f, 0x0, 0x1e, 0x7, 0x9c, 0x7,
errordeveloper 11:bdf601a405fc 30 0xc0, 0x3f, 0xf8, 0xf0, 0x3e, 0x0, 0x3e, 0x3,
errordeveloper 11:bdf601a405fc 31 0xdc, 0x7, 0xc0, 0x1f, 0xe0, 0xf0, 0x1e, 0x0,
errordeveloper 11:bdf601a405fc 32 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 33 0x1e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 34 0x0, 0x0, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 35 0x0, 0x0, 0x0, 0x0, 0x3c, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 36 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0xf8, 0x0,
errordeveloper 11:bdf601a405fc 37 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1,
errordeveloper 11:bdf601a405fc 38 0xf8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 39 0x0, 0x1, 0xf0, 0x0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 40 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
errordeveloper 11:bdf601a405fc 41 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
errordeveloper 11:bdf601a405fc 42 };
errordeveloper 11:bdf601a405fc 43
errordeveloper 11:bdf601a405fc 44 inline void lcd_print_xively_logo() {
errordeveloper 11:bdf601a405fc 45 static Bitmap xively_logo = { 80, 32, 10, xively_logo_data };
errordeveloper 11:bdf601a405fc 46 lcd.cls();
errordeveloper 11:bdf601a405fc 47 lcd.print_bm(xively_logo, 24, 0);
errordeveloper 11:bdf601a405fc 48 lcd.copy_to_lcd();
errordeveloper 11:bdf601a405fc 49 for(int i = -32; i < 32; i++){
errordeveloper 11:bdf601a405fc 50 lcd.cls();
errordeveloper 11:bdf601a405fc 51 lcd.print_bm(xively_logo, 24, i);
errordeveloper 11:bdf601a405fc 52 lcd.copy_to_lcd();
errordeveloper 11:bdf601a405fc 53 wait(0.1);
errordeveloper 11:bdf601a405fc 54 }
errordeveloper 11:bdf601a405fc 55 }