A Simple Interface for the Internet of Things
Awhile back I bought the Adafruit starter kit for the LPC810.LPC811 on a TSSOP-16 breakout board |
With much trial and error I was able to get a simple serial communication with it through a ttl usb cable. I then wanted to control the I/O remotely. This device can be polled for status and controlled through tcp messages from your Android/iOS device and Raspberry Pi
My Remote Control portable plug
Parts:
- 1 - LPC810
- 1 - HLK-RM04
- 1 - ULN2803APG
- 3 - 1k ohm Resistors
- 1 - 120v to 5v 500mA converter module (ebay)
- 1 - 2Ch relay module
- 1 - prototyping board
and connected it all up:
simple code for controlling my plugs in python:
import socket class PlugPoller(threading.Thread): def __init__(self,ip,port): threading.Thread.__init__(self) self.ip=ip self.port=port self.connect(ip,port) self.status='0000' self.command='!getstat\r' def connect(self,ip,port): try: self.s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.s.settimeout(1) self.s.connect((ip,port)) except: pass def run(self): while True: try: sleep(.1) self.s.send(self.command) self.status=str(self.s.recv(4)) #print "data:{"+self.command,self.status+"}" except: print 'error' sleep(5.0) self.connect(self.ip,self.port) pass if(self.command!='!getstat\r'): #print self.command self.command='!getstat\r' def getstatus(self): return self.status def sendcmd(self,c): try: self.s.send(c) except: pass return self.s.recv(4) def main(): plug=PlugPoller("192.168.16.254",8080) plug.start()#start the async status poller plug.sendcmd('!turnon1') #turns on relay 1 plug.sendcmd('!trnoff1') #turns off relay 1 plug.getstatus() #returns a status of 0001, first two binary numbers are the button inputs the last two are the relays plug.sendcmd('!talloff')#turns off all relaysWhenever these inputs are pressed it will toggle the relays locally. The pushbuttons would be connected to the right side of the Wifi Module. Giving you remote and local control of your device without having to put an Arduino or Raspberry Pi in that enclosure.
For me I like knowing instantly whether my light is on while looking at it remotely. The PlugPoller python script is polling statuses every tenth of a second. The MCU and the module talk at 115k baud so you can get your results pretty quickly.
Since that looked pretty ugly (prototype), i'm currently working with the LPC811 which has more I/O. 14 configurable pins, 2 of which I will use for UART communication (12 for I/O pins) which will let you sense more inputs and turn on more outputs. These chips can have some of these pins configured for i2c and spi that can connect you to 100s of sensors that you can have through wifi.
Please Comment if you wish to see this as a kit you could buy
Or if you have questions
No comments:
Post a Comment