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 Gerardo CR

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

Files at this revision

API Documentation at this revision

Comitter:
emilmont
Date:
Tue Jun 04 16:06:35 2013 +0100
Parent:
4:4aa1faf9363e
Child:
6:36dfad519099
Commit message:
Point to the latest libraries

Changed in this revision

EthernetInterface.lib 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 Mar 01 15:45:30 2013 +0000
+++ b/EthernetInterface.lib	Tue Jun 04 16:06:35 2013 +0100
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#9b2d10dc0392
+http://mbed.org/users/mbed_official/code/EthernetInterface/
\ No newline at end of file
--- a/mbed-rtos.lib	Fri Mar 01 15:45:30 2013 +0000
+++ b/mbed-rtos.lib	Tue Jun 04 16:06:35 2013 +0100
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#53e6cccd8782
+http://mbed.org/users/mbed_official/code/mbed-rtos/
\ No newline at end of file
--- a/mbed.bld	Fri Mar 01 15:45:30 2013 +0000
+++ b/mbed.bld	Tue Jun 04 16:06:35 2013 +0100
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/3d0ef94e36ec
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/
\ No newline at end of file