IOT Push Button (Like Amazon Dash)

Amazon Dash button is an incredible piece of hardware and another example of “applied engineering” in Amazon, just like Kindle.

The inspiration for this project isn’t directly derived from amazon dash, I wasn’t aware of it until I started digging the internet but at end, I had to set the performance goal to Amazon dash, because no other piece of hardware was up to mark. A detailed teardown of dash button can be found here.

So, Since “decades” I wanted to build some piece of hardware which I could dynamically program for any functionality like playing next youtube video, unlocking door, rebooting a machine, minimizing all open tabs or whatever with a push of a button. The button should be portable and independent of device for operation.

To meet my requirements I had to remove BLE or any other radio-based technology which needed a receiver or additional unit to operate. ESP-12F is power intensive and somewhat large if compared to esp-01.  The end prototype looked like this and worked as expected.

Below is list of components I used.

  • 1x LiPo Battery – 150mAh
  • 1x ESP8266-01
  • 1x 1k Register
  • 1x Tactile Switch Button

You might require a soldering iron with fine tip, basic desoldering skills, access to 3d printer, FTDI board or similar setup.

The schematics of setup would look like below:

The functioning would be like – We turn on ESP using push button, but it would take time to log in to wifi, authenticate – so we need to keep it on for pretty long time – which could be done by using programming output pins, As soon as ESP turn on GPIO2 can be set to HIGH, Once operation is finished it can be set to low. Few challenges which I found on way (with fixes):

  • Power is very limited – So we need to remove LED’s from the esp, this would save a lot of power and would increase battery life by almost a fold!
  • You should use diode and transistor to limit current, since I am not an electronic nerd I would not comment on it.
  • You should set a timeout period, in case you are writing custom logic else battery will drain and you will never come to know why!

After soldering – You have to upload following code which need to be tweaked according to need, but it has basic logic code –

The code can set in hotspot mode if couldn’t connect to wifi and if could connect it would make a connection to mqtt server and make an announcement then shutdown.

I hope you enjoyed the article, it wasn’t a detailed writeup and I dropped many details – but if you have any questions you can comment or drop mail – I will surely help.

Cheap BLE : JDY-08

Disclaimer : This post is based on my experience which is completely subjective, in no way I am promoting any application or product ūüėČ

 

I have been trying to get my hands into BLE4.0 modules since long. As always I was looking for small, cheap solution, JDY-08 was one of solution I came across – it seemed just Perfect !

JDY-08
JDY-08 Module

It is based on TI-CC2541 SOC, Low power consumption – long range Voila!

Below is what is being advertised by most vendors:

  1. maximum transmit power of 0db, the maximum transmission distance of 80 meters.
  2.  support serial allowing users to modify the device name through AT commands service UUID, transmit power, pairing password instructions, convenient to use and flexible.
  3. Ultra-low standby power consumption 400uA ~ 800uA
  4. Ultra-long connection distance 100 ft / 60 m
  5. Fast reaction speed 0.4 secondsFor Apple, AndroidReceive no byte limit, up to 6K Bytes/sec.

I quickly ordered 10pcs without a second thought.

Below is what you should keep in mind:

  1. Datasheet, documentation – everything is in Chinese! Cool !
    Luckily, Few folks did translation –¬†https://docs.google.com/document/d/14mHWT3GhELCj-6yxsam0k5bjzazq8nnPoz4B_gYh04k
    Also, you can check http://forum.arduino.cc/index.php?topic=432074.0 because this is the only helpful resource in the web.
  2. Firmware is broken – at least for me, some other user confirmed same in above Arduino thread.
  3. No other support.
  4. Non-standard board pitch, you cannot use header pins

But it is good in many ways:

  1. Small size, thin, light, small – cool!
  2. If you use HC-05 or HC-06 for transparent communication, you can use GATT terminal for transparent communication.
  3. Very low power consumption – from my tests, I found 0.5ma consumption.
  4. Long range Рupto 30meters without optimization.
  5. iBeacon mode – works fine – but power consumption was 0.5ma

I was unable to test as I could only use GATT write & notify methods, AT commands to change mode & device name, even AT+RST returned ERR.

You can use following tools to test :

Below is schematic I followed:

 

 

 

Adding a display over network !

You are doomed if your laptop has only one HDMI Port & you are running Linux in that box.

Unlike windows – where there are tons of easy to run solution, & there are still tons of solutions if you have big numbers in your pocket.

Certainly – I neither wish to spend money on external VGA/HDMI extender or docking station nor to change OS. So after googling a lot I discovered a solution which utilized a different machine to act as the streaming client. You can use RPI or an old p4 machine.

Below is how it works.

  1. Adds a virtual display on your machine, usually all graphics card support at least one virtual display.  You do all this using xrandr
  2. Create a VNC Server to stream that display – but since you cannot each time run two commands just to connect display – we are running VNCViewer in listen mode
  3. Connect to vnc viewer & keep running it in the background.

You Laptop —[Display Data]—> Network —-> VNCViewer

As suggested above you data is being streamed over the network ¬†– you cannot run 4k data. But if you have good Lan speed you won’t face any problem.

I have also optimized settings for best experience – so far I can use terminal, watch videos – the only drawback is you feel the lag when you use keyboard or mouse for realtime feedback.

In Client Machine, i.e. your laptop.

You will need to install x11vnc & screen

In server Machine (LAN address 10.0.0.2)

You will need to install VNC Viewer in client side.

Just Another DIY “Smart” Watch

Note : This article was written after project was partially completed, so i don’t have better images.

There are hundred’s of projects for building “Smart watch using arduino”, I have curated a list of better projects at end of this article. I didn’t plan to copy any of given projects but at end it turned out that world is a big place. So this blog post is my effort in developing “My smartwatch”.

Hardware :

  1. Arduino Pro mini
  2. Bluetooth module (HC-05)
  3. OLED Module (SSD1306)
  4. LiPo Battery (110 mAh)
  5. Thin copper wire, single strand if possible.
  6. FTDI Breakout board or any way to program Arduino pro mini.
  7. Micro USB female pins
  8. Membrane Tape

Tools :

  • Soldering iron – along with soldering wire, flux, etc.
  • 3d Printer/Good Crafting Skills to make a case
  • Working brain ! (Recommended)

Software :

  • Android Phone (BTTerm) /Linux System(minicom, rfcomm), Windows Phone, Windows *, Mac OS Users are on their own but you can search for “Bluetooth serial terminal”
  • Arduino IDE
  • Common Sense ! (Recommended)

The guide here is definitely not a step by step guide, it just tells the flow (an algorithm not code).

  1. Desolder pins in your OLED display. Yea, all header pins.. for noobs like me it’s a tough task.
  2. Desolder pins of HC-05/HC06 if it has, if you got module without header, skip
  3. Connect all GND, VCC pins of arduino, hc-05, oled Easy ?
  4. Solder oled pins SCL -> A5, SDA -> A4  to arduino.
  5. Solder hc-05 pins  TX -> 10, RX -> 11  to pro mini.
  6. Then Solder VCC with a switch (Any you prefer) & to battery.
  7. Upload the code
  8. Connect to HC-05 using phone & send any data.

    HC-05 Soldered

Oled, HC-05, ProMini Stacked.

 

 

 

 

 

 

Everything stacked Packed

Back View

Front View

 

 

 

 

 

 

 

 

 

Click here to watch working video.

Below is arduino code :

 

As told initially my build is not the best one, there are people with better electronics & better output check these :

http://www.instructables.com/id/Make-your-own-smart-watch/?ALLSTEP

http://makezine.com/projects/make-43/open-source-smartwatch/

http://www.tinkernut.com/portfolio/make-smartwatch-old-cell-phone-part-1/

http://oswatch.org/mkII_build_page_1.php

https://hackaday.io/project/12876-chronio

http://blog.zakkemble.co.uk/diy-digital-wristwatch/

Kindle Universal Dashboard

Kindle is Super awesome !

Because of its e-ink display. I wanted a display to¬†present data which has¬†– Least power consumption, Not painful to eyes & obviously one which doesn’t emit blue light.
E-Ink displays fit perfectly to my requirement – acquiring a display which can be driven using Raspberry Pi or Arduino is hard, size/cost ratio is much higher.

On googling I found some display modules which were more or near to 70-80$ – even smaller display – which impulsed me to get a Kindle Touch (8th Generation) at around 74$ approx.

Kindle - MadhurendraKindle comes with an experimental browser but it is narrowed version of WebKit, which is pretty useful if you want to display static content or just want to make a control panel, it can easily render normal websites which use js/CSS & works pretty well.¬†But support for HTML5 is almost absent¬†– so you can’t use WebSockets to push data, using long polling/fast polling is only solutions so far.

Moreover, there was another problem which I had to fix¬†–¬†Kindle has fixed timeout which sends it to sleep mode – for mine it was 10min, after digging I found you can use ~ds or similar but for me, nothing worked.

We can only hope that support to remove timeout or change timeout period will be added in future releases. I think old kindle supports.

If you can’t change timeout or you want to use few other features I suggest you to jailbreak. Follow steps mentioned here¬†http://www.mobileread.com/forums/showthread.php?t=275877 , Don’t jump, It works for kindle touch 8th generation. Tried, tested, working ! ¬†For KT3 you will need to install¬†MRPI along with¬†KUAL. Once done your kindle is officially out of warranty¬†ūüėÄ . Post that you need to install¬†USBNet¬†– it will ¬†allow you to ssh to your kindle. ¬†All this will allow you to execute “lipc-set-prop com.lab126.powerd preventScreenSaver 1″ this on the kindle. It will simply disable screensaver. ūüôā

Once you have your kindle whose screen doesn’t lock¬†you can simply go & execute ¬†a simple nodejs script to push data.

Note : Kindle doesn’t support¬†WebSocket & none of transport methods in socket.io except “polling”.¬†

Below is nodejs server code :

Below is code of client.html

Voila – It works !

Below is video of working ¬†in case you want to see demo before getting hands dirty ūüôā

Warning & Update : This method might consume more power than expected, as experimental browser has loading status Рwhich continuously refreshes a section of the screen. To overcome this problem I will be polling server with long interval difference Рwhich will be adjustable by the server.

Note for nerds :¬† Since this method uses browser – it’s more flexible – but if you are possessive about power consumption & screen space – You can use JAVA to develop kindlet application. Lightweight pub/sub protocols like MQTT¬†should help you in the¬†way.


photo_20161030_124622Designing a wall holder : 
You can google for covers or design own or use some double sided foam tape. Since i had access to 3d printer i got two of http://www.thingiverse.com/thing:832273 printed & hung it on the wall Рit just helped me in reading few books apart from using it only as display. SWAP!    

Use it as :

  • Scoreboard
  • Notification
  • Weather system
  • Wallpaper slideshow
  • News/RSS feeds display
  • Home automation control
  • Anything
  • Book reader ūüôā

At the end, even if you place it behind your monitor it won’t hurt or push the new data to your eyes & spoil the code castle you were building.

Offline Wikipedia with Elasticsearch and MediaWiki

Wikipedia is Awesome ! It’s open, its free – Yea. & its huge in size, millions of articles¬†¬†but as developer how to exploit the free knowledge.

I started digging internet just to find ways to exploit my fresh 9+ GB of XML Gzipped archive which seemed to me of no use as even a simple text editor can’t open it. (Just out of excitement what’s inside, how its structured, Schema ! )

Luckily people have already imported it. Elasticsearch is fast, reliable & its good for searching, so https://github.com/andrewvc/wikiparse was a saver.

  • Installed elastic search
  • Ran command to import

it took almost 48 hour in an i5, with 8gb ram – where mistake was i used same harddisk for data storage & database. Time might vary.

Data was imported but its still of no use ! Why ? Its in text/wiki format, parses is needed.

After doing search only solution i found was using mediawiki api, which is in PHP there were lots of things missing as its only for mediawiki but not for parsing plain text. (Though i didn’t spend much time in learning internal API)

I quickly downloaded mediawiki, ran nginx with php, installed it & used API.php.
it was good to see my offline API too, but still many things were missing, confusing, API has hard to modify structure. So i created a parse.php

So all steps were :

Backup Server Configurations to Git

When you have multiple servers it pain to remember every configuration and it may take hours to configure servers again incase you need.
It is also impractical to copy each files.

There are few tools available but they come with overhead attached moreover its fun to write custom solutions ūüôā

1. Create directory
2. cd into it.
3. Initialize git
4. Add a remote
5. Create branch specifically for that server
6. Check out branch
7. Add shell script
8. Make a commit and push to server.

Content of backup.sh

Then, Don’t forget to generate SSH key adding key to your git server.

Now i can either setup a cron job or add command to daily backup script to update configuration files.
using

from remote.

Cloning Server to New Hardware

You can find many ways of cloning old server to new hardware, create diskimage and move to new hardware and if you have identical hardware use dd or similar tool to copy disks block by block, but if you have new hardware and want to move server without downtime and with no configuration change there is nearly no solution.

I used vestacp, ejabberd in my servers so i had to make changes even after moving some files, as IP changes every where but it is still far better solution than installing and configuring each package manually.

We used rsync to copy whole server to new server except following files
because on new network you will never wish to propagate old network configuration,device specific configurations, installation specific configs.

/boot/
/lib/modules
/etc/fstab
/etc/mtab
/etc/modules
/proc
/dev
/etc/network/interfaces
/root

Create a file with following directories and then execute rsync with exclude-from.

rsync will Synchronize all your files from remote to local.

Monitoring Website for Downtime

Sometimes our in house server go down, But at production level we cannot take risk of 1min downtime, so we were supposed to monitor our server for downtime.
Although there are many cheap services available but i decided to do it my own way, I can use this script in my RPI to monitor even my internal services.

Below is python code, Which sends email if a server goes down and when it comes back online. Obviously you can add code to get more statistics like Logging to file, average response time, Monitoring page changes, Downtime etc.

After saving code to server use cron job to start run script on every boot.

Edit crontab using sudo crontab -e and then add following line to file.

@reboot screen -dmS monitor python /root/monitor.py &> /dev/null

Above command starts a screen session named monitor and forwards error of screen to null.
Incase you want to see output of monitor.py use screen -r monitor.
You can also add it simply without screen like
@reboot python /root/monitor.py &

If you have some suggestions comment.