Tuesday, September 6, 2016

5$ TV Remote Control Using Smart Phone

I have following goals for controlling my Infrared Controlled Appliances:
  • Towards the goal of the controlling my TV, Set-Top-Boxes,AC,etc, at lower cost less than 5$ (or even go less in case one has  more IR appliances or one has already a raspberry/chip in home for Home Automation/IoT works) per device. I am leaving the cost of central controller, whose cost would be around 9$.
  • Design/Develop an Open Sourced system like LIRC project that controls the IR appliances using smartphone and WiFi(there by avoiding line of contact issues in IR based remote controls)
  • Make any old TV(including CRT TV and LED TVs that are not smart TVs,etc) to be  controlled from any smart phone
  • Also ensure that smartphone SHOULD not require  IR  based emitter (as smartphones with IR transmitter are little costlier)

To achieve these goals,  I have designed and tested initial version of my Centralized Home IR Appliances control system that can adapt and control different IR appliances at very cheap cost. The system has following features:
  • It is cheap
  • It Generic and one can add any number of IR devices
    • All one has to for adding new IR appliance is to add the IR codes in form of property file
  • Works with most of the smartphone (at present only android phones)
  • Gives generic REST based interfaces to control these appliances (TODO)
  • Gives generic RBAC control of these IR appliances (TODO)

For implementing initial working prototype, I chose:
  • Common costs for all IR appliances in a Home
    • 9$ Chip Computer as central control system where all Smart Phones sends commands . This device is common for all IR appliances in home (that are in same WiFi network). Though  I have chose 9$ chip-computer, once can use Raspberry-PI or any computer that run python.

  • 2A Power supply for each IR transmitter 2$ (approximate)
      • Per IR appliance costs for IR Transmission
        • For each IR appliance, I have put one ESP8266 device to send IR commands (which costed me 2.82$). For each IR appliance , we need to this board (in case if both appliances are not in same IR visibility)
        • I bought one IR Transmitter for 1.1$ (approximate) 
        • Power supply for each IR transmitter 1.1$ (approximate)

      At present the system control my TV and set-top-box. In future, I am going add more devices like my LG-Air-Conditioner

      I have put code in 3 projects in Git-Hub:

      Tuesday, August 16, 2016

      Programmatic Add and Removal of USB devices in Linux

      As a part of setting up my 9$ CHIP computer, I was running my chip from 500 mA/1000 mA power sources and sometimes the CHIP stops during startup due to high current consumption.

      To stop chip from stopping CHIP during boot I had taken following steps:

      1. Ensure the power supply is good and at least 1000 mA
      2. Ensure that CHIP is connected to a LiPo battery, so that battery can supply burst current situations
      3. Added /etc/systemd/system/no-limit.service 
        1. This is nothing but execution of axp209 --no-limit during CHIP-booting by systemd
      4. Stopping USB hubs and USB devices during startup programatically
        1. Write systemd scripts for using above script -- TODO

      To achieve the 4th step, one  has to programmatically detect  USB devices on USB Hub and stop them. Later once startup is finished, start the USB devices programmatically.

      So I write one helper script that does this job automatically and this code can be read at github

      This script might be used for non-USB devices(might need some modifications). Though tried and tested on CHIP, it might run on PCs and other Linux boxes with little modifications. If you have suggestions/modifications, please let me know or update in git.

      Monday, August 15, 2016

      Data mining by Python script to get data from 9$ Chip's battery health

      I got finally my 9$ chip boards. Fortunately this boards comes with LiPo battery connector and charging IC (named axp209). One can query this chip's i2c subsystem by i2cget/ic2set commands to get the data about system's battery status like:

      • Battery voltage
      • Charging current
      • Battery connected
      • Battery charging
      • etc
      NTC provides a shell script that fetches above data. But running this script in daemon mode and collecting data from multiple chips (which are in network) would put  strain on CPU/battery resources of chip as this script executes almost 50 unix processes for getting 10 sensor values and it also might drain battery (when main power goes off AND monitoring scripts should not drain resources).

      As I am going to monitor system using other python scripts as well, I started porting the axp209 script to python script using i2c-tools/py-smbus module. But this porting does not work in  python as smbus python-module does not provide forceful read/write of i2c-device addresses (for safe reasons). 
      Similar options were provided in command line tools of  i2c-tools (like i2cget, i2cset, etc). So I have hacked  i2c-modules/py-smbus code and changed/added 3 lines to get similar forceful opening in smbus module of python.

      Changed i2c-tools/py-smbus code is at github

      Using the above  modified smbus module, I wrote python script that collects 9$ chip data in daemon mode. Source code is at github

      This changed i2c-tools/py-smbus code can be used for raspberry pi as well (one has to change i2c-bus and device addresses accordingly)

      Warning: Developer should be aware that forceful read/write of i2c devices can lead to dangerous consequences (if done unknowingly/inappropriately/etc). So developer is responsible for using this changed code :)

      Wednesday, July 13, 2016

      Get Current Time from Bed while sleeping (without seeing Watch/Phone) by simple Hand waving

      As a part of  Home Automation jobs, one of my use case is:

      • Know the current time in night (in pitch dark room)
        • with following requirements
          • I am still sleeping 
          • I don't want to open my eyes for seeing time on watch/phone
          • My phone or watch are 4 meters from bed, I don't want to go to that place to pickup phone/watch
      So thought that let me use latest hot/cheap wifi-chip ESP8266 (NodeMCU version) to do this job.

      I used a Passive Infrared Sensor (PIR - ~1$) , ESP8226-NodeMCU-Board ( ~4$) and Android phone (~your capacity)  for this purpose.

      • PIR 
        • Will sense any movement. I had kept this sensor at back of bed. If I wave my hand near PIR sensor, it will sense and give input to ESP8266 Chip
      • ESP8266
        • This will work as WiFi Access Point for Android mobile
        • Runs embedded firmware to sense the PIR reading & debouncing the PIR signal
        • Sends a HTTP call to Android Phone for speaking the time 
      • Android Phone
        • It will connect to WiFi-AP (from above ESP8266 )
        • It works as HTTP-Server for requests from ESP8266
        • It will run a Speaker service for any incoming requests from ESP8266
        • Ensure that works when phone in deep sleep mode

      I have finished 3rd version of the code (FW at ESP8266 & Android-App in Smartphone). I will put code and pictures in the weekend.

      Thursday, July 7, 2016

      9$ Chip Computer is posted from hongkong

      Finally my 9$ computer chip-board is dispatched (after whole manufacturing and testing is finished by the chip manufacturer) today from Hongkong. It might arrive after 1 or 2 weeks.

      What is this 9$ Computer from Nextthing.co

      It  has following important specs (I am putting my comments on  w.r.t. Raspberry computer):
      • 9$ System-On-Chip board9Soc Board) that runs most of the modern Linux OS ditsributions -- Raspberry costs 35$
      • It is powered by 1GHz ARM processor
      • 512MB RAM
      • 4GB Flash Space (which can be used as booting medium for OS,applications, etc) -- Raspberry does not have it, we need to use SD-card
      • WiFi  -- Only Raspberry 3 has WiFi
      • Bluetooth 4.0 -- Only Raspberry 3 has  Bluetooth 4.1
      • GUI
        • HDMI port -- can be connected to any modern TV/monitor
        • RCA connector -- can be connected to any old TV
      • Power charging processor  -- Raspberry does not have this vital part for standalone IoT system
        • Which can take power from 5V and supply processor
        • Concurrently charge a Li-Po battery while taking power from 5V power supply
        • If power supply goes off, run the CPU with Li-Po battery without a reboot
      • USB ports 
        • Connect to USB key boards and USB mouse.
        • Also connect to USB flash disk and portable Hard Drives (please keep in mind to not to excess 500 mA when powered from a USB hub)
      • By default comes with Linux-OS (without any OS loading from user part) -- on raspberry we need to load OS
      • Has power switch -- raspberry does not have power switch :(
      • Power from external Li-PO battery
      • Has a camera interface. USB cameras are also can be connected
      • General Purpose IO pins (GPIO) for doing IoT stuff
      • Good development echo system
      • Open sourced (mostly) drivers and Linux kernel

      What way it is useful to you

      • Use it to convert your HDMI/RCA/CRT-TV as Smart-TV
      • Run as a computer and connect to your TV monitor
        • Browse Internet without starting Laptop/PC on your TV
      • Use it for Internet of the Things (IoT)
        • Killer point is it has Power supply unit that allows it to be powered from a Li-PO battery
      • Use it for educating your kid on Linux (just like Raspberry does )
      • Use it for reading e-books from TV monitor (though it is not recommended due to eye-strain)
      • Use it for streaming Video from your Laptop/PC to TV
      • Possibilities are limitless -- only your imagination can stop :)

      Documentation and Links

      So please use this super affordable chip that can do a lot (based on your needs and imagination) for you.