iot and Robotics
My journey with iot and robotics (In Progress...)
I have been working in the data warehousing and Big data domain from quite a while and I did not get a chance to explore one of my childhood fantasy until, I went to my friend - Uday's home in Bengaluru to visit him. He introduced me to the world of IOT. I was awestruck when I saw a small pot lying on his desk and some electronics attached to it. When asked, he started explaining me that it was a humidity sensor and he would know from his office if some one watered the plant at home. That was fascinating. There was a weighing machine in his home which displays the weight on his computer and he records the time and weight information so that, he can analyze the information later. That was neat, as he do not have do a thing other than standing on the weighing scale.
I have got some inspiration from him but, I do not have any knowledge in electronics.
1 Temperature and humidity sensor using NodeMCU
init.lua
function startup() if file.open("init.lua") == nil then print("init.lua deleted or renamed") else print("Running") file.close("init.lua") -- the actual application is stored in 'application.lua' dofile("application.lua") end end print("10 secs to abort.") print("Waiting...") tmr.create():alarm(10000, tmr.ALARM_SINGLE, startup)
application.lua
pin = 3 status, temp, humi, temp_dec, humi_dec = dht.read(pin)--read dht11 from pin if status == dht.OK then --check status is ok and print temperature and humidity print(string.format("DHT Temperature:%d.%03d;Humidity:%d.%03d", math.floor(temp), temp_dec, math.floor(humi), humi_dec )) elseif status == dht.ERROR_CHECKSUM then --else print either status print( "DHT Checksum error." ) elseif status == dht.ERROR_TIMEOUT then print( "DHT timed out." ) end
2 Remote controlled car using Arduino uno
// Controlling RC with computer keyboardimport time import paho.mqtt.client as paho import sys,tty,termios broker="192.168.8.88" #broker="iot.eclipse.org" #define callback def on_message(client, userdata, message): time.sleep(1) print("received message =",str(message.payload.decode("utf-8"))) client= paho.Client("client-001") #create client object client1.on_publish = on_publish #assign function to callback client1.connect(broker,port) #establish connection client1.publish("house/bulb1","on") ######Bind function to callback client.on_message=on_message ##### print("connecting to broker ",broker) client.connect(broker)#connect #client.loop_start() #start loop to process received messages #print("subscribing ") #client.subscribe("house/bulb1")#subscribe #time.sleep(2) class _Getch: def __call__(self): fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(3) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch exit_pressed = 0 print("waiting for key press") def send_cmd(cmd): client.publish("HOME/robot/cmd",cmd)#publish def get(): inkey = _Getch() while(1): k=inkey() if k!='':break if k=='\x1b[A': print ("FRONT") send_cmd("FRONT") elif k=='\x1b[B': print ("BACK") send_cmd("BACK") elif k=='\x1b[C': print ("RIGHT") send_cmd("RIGHT") elif k=='\x1b[D': print ("LEFT") send_cmd("LEFT") else: print ("not an arrow key! exiting") exit_pressed = 1 while (exit_pressed==0): print("waiting for key press") get() print("Exiting..") client.disconnect() #disconnect client.loop_stop() #stop loop
3 Spider - 12 motor 4 legged robot using Arduino nano
4 E-Bike- Assembling e-bike kit
5. Raspberry Pi temperature using homebridge and Homekit [03 Sep 2019]
STEP 1 : Connect to your Pi using ssh
ssh pi@raspberrypi.local
STEP 2 : Update pi
sudo apt-get update sudo apt-get upgrade
STEP 3: Install node and npm (follow https://www.instructables.com/id/Install-Nodejs-and-Npm-on-Raspberry-Pi/)
Detech model of the ARM processor of Pi (ARMv6, ARMv7 or ARMv8)
uname -m
STEP 4: Depending on the version, go to this page (node.js download page) and copy the link of corresponding. For instance, mine is ARMv7
wget https://nodejs.org/dist/v10.16.3/node-v10.16.3-linux-armv7l.tar.xz
STEP 5: Extract the archive
tar xvf node-v10.16.3-linux-armv7l.tar.xz
STEP 6: Copy Node to /usr/local
cd node-v10.16.3-linux-armv7l/ sudo cp -R * /usr/local/
STEP 7: Check the versions of node and npm
node -v
npm -vSTEP 8: Homebridge installation
curl -sSL goo.gl/Ksdhph | bash
STEP 9: run Homebridgehomebridge
hit cntr + C to get back to PiReference: https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi
STEP 10: Running Homebridge on Bootup (systemd)
Download 2 files: https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/
Download the two files and place homebridge under /etc/default and
homebridge.service under /etc/systemd/system on your Raspberry Pi from above link
STEP 11: Configuration
In order to use the systemd service as is, the following folders and user have to exists:
Create a system user named homebridge. You can easily create this user with
useradd --system homebridgeLater, change the user permission from root user to homebridge
chown homebridge:homebridge homebridge
STEP 12: A directory called /var/lib/homebridge, writable by the user created above, and a corresponding config.json file in that directory. Homebridge by default looks for its configuration in /home/<username>/.homebridge. This is unsuitable for services and the -U /var/lib/homebridge flag ensures the config is read from a different place.
Here is the code for config.json. For validating json code use https://jsonlint.com/
{ "bridge": { "name": "Homebridge8", "username": "CC:22:3D:E3:CE:30", "pin": "031-45-154", "port": 40853 }, "accessories": [{ "accessory": "RaspberryPiTemperature", "name": "RaspberryPi CPU Temperature", "updateInterval": 1000 }] }
STEP 13: Install homebridge plugin for Pi temperature
sudo npm install -g homebridge-raspberrypi-temperature
STEP 14: Now Enable and run the service (first time) with the following commands:
sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge
STEP 15: check the status of the service by calling
systemctl status homebridge
STEP 16: On subsequent reboots, it should start automatically, if not, use the following command to check the error cause.
journalctl -u homebridge
STEP 17: When the service starts successfully. It might look something like thisNow you can open your homekit and enter the code
Once done, you can now see the temperature showing up in your HomeKit App :)
Comments
Post a Comment