![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Basic example using a TCP protocol. Client version. It connects to a Raspberry Pi server using a Python Script.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of TCPEchoClient by
Basic program.
It connects to a remote server on a LAN running a Python script. Server send data to a spreadsheet in my google docs account.
PYTHON CODE
PYTHON CODE
#!/usr/bin/python import time import datetime import sys import gspread import socket # Socket port = 50006 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', port)) s.listen(1) # Google Acoount Details email = 'your-email@gmail.com' password = 'your-password' spreadsheet = 'ldr' # Login with your Google account try: gc = gspread.login(email, password) except: print "unable to login in. Check your email address/password" sys.exit() # Open a worksheet for your spreadsheet using the filename try: wks = gc.open(spreadsheet).sheet1 except: print ("unable to open the spredsheet. Check your filename: %s") % spreadsheet sys.exit() time.sleep(1) input = 0 conn, addr = s.accept() print 'Connected by', addr while True: input = conn.recv(1024) print(input) print(datetime.datetime.now(), input) print('write angle to gdocs') try: values = [datetime.datetime.now(), input] wks.append_row(values) except: print ("Unable to append data. Check your connection?") sys.exit()
History
.;
2014-11-07, by gerardo_carmona [Fri, 07 Nov 2014 05:28:31 +0000] rev 7
.;
Update to the latest libs
2014-05-14, by Kojto [Wed, 14 May 2014 15:24:47 +0000] rev 6
Update to the latest libs
Point to the latest libraries
2013-06-04, by emilmont [Tue, 04 Jun 2013 16:06:35 +0100] rev 5
Point to the latest libraries
Update libraries
2013-03-01, by emilmont [Fri, 01 Mar 2013 15:45:30 +0000] rev 4
Update libraries
Update socket library
2012-08-01, by emilmont [Wed, 01 Aug 2012 13:03:13 +0000] rev 3
Update socket library
enable string terminator; update socket library
2012-07-26, by emilmont [Thu, 26 Jul 2012 16:45:55 +0000] rev 2
enable string terminator; update socket library
First implementation
2012-07-26, by emilmont [Thu, 26 Jul 2012 10:10:48 +0000] rev 1
First implementation
Template for TCPEchoClient example
2012-07-26, by mbed_official [Thu, 26 Jul 2012 10:04:15 +0000] rev 0
Template for TCPEchoClient example