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()
Changes
Revision | Date | Who | Commit message |
---|---|---|---|
7:a6f3768bc4b7 | 2014-11-07 | gerardo_carmona | .; |
6:36dfad519099 | 2014-05-14 | Kojto | Update to the latest libs |
5:529642dd94c3 | 2013-06-04 | emilmont | Point to the latest libraries |
4:4aa1faf9363e | 2013-03-01 | emilmont | Update libraries |
3:3fbf0efec25a | 2012-08-01 | emilmont | Update socket library |
2:563aa530f0dd | 2012-07-26 | emilmont | enable string terminator; update socket library |
1:a51d8ed156e6 | 2012-07-26 | emilmont | First implementation |
0:e8f884c94549 | 2012-07-26 | mbed_official | Template for TCPEchoClient example |