Thursday, February 1, 2018

A few months ago, I got my hands on ESP8266 Black cloud features Board T5 which has an ESP8266, an 8051 microcontroller and a few sensors. The 8051 microcontroller acts as a master to the ESP8266 and comes loaded with a demo program which is supposed to work with some android app. ESP8266 can be directly programmed using Arduino, so it would be better if I would reprogram the 8051 to act as a slave connected to ESP8266. The ESP8266 will run an Arduino sketch (that I would write) and ask the 8051 for the sensor readings (over UART). To do that I would need to program the 8051 with come C program that I have written.

So the first step was to learn how to compile a simple blinky program for the 8051 and be able to download and run it on it.

STC15L2K32S2 has two UARTs (Serial Ports). One is connected to ESP8266 and the other one is brought out on the 3 pin header. The one brought out on the 3 pin header can be used to reprogram the microcontroller using the STC's ISP utility (In System Programming)

Use the STC utility to install headers for STC microcontrollers to Keil. Keil doesn't come with support for STC microcontrollers built-in.

Use the STC utility to generate demo code for controlling PWM on STC15L2K32S2. Instead of copying the C code, click "Save project" to save a Keil C51 project - that way all the settings are exported as well.

Open the project in keil and build the project by pressing the F7 key. Hex file will be generated. The evaluation version is limited to generating 2kB of code, which is fine if you just want to blink LED using the PWM feature of STC15L2K32S2.

Go back to STC utility, select the MCU type as STC15L2K32S2

Select the appropriate COM Port

Load the hex file onto the STC utility (click Open Code File)

While the Black board T5 is connected to your computer via the CH340 board, keep the batteries installed in Black board T5 but keep it powered off

Click on "Download/Program" in STC utility

Turn on the power via the slide switch on the black board and watch the program download.

Once the program is complete, the code will run and LEDs will fade in and out.

Wednesday, January 10, 2018

One of the big issues with IoT is somehow enabling two end nodes to communicate with each other in the presence of Network Address Translation (NAT)
Now days most ISPs (and Mobile Network Operators or MNOs) use NAT by default and assign you local IP addresses in 10.*.*.* subnet. You usually have to pay an extra fee to get static global IP addresses assigned to you - this could be a security concern.
If your end nodes run embedded linux, the following solutions can be used:

Use DDNS and UPnP togetherDDNS is not usually free, but the manufacturer of your embedded linux device (routers from goodlife of Vstarcam's IP camera) might provide you this service for free as it uses almost nil resources on the server side. Most ISPs have UPnP support disabled on their gateway. In a home environment, if you have your own static global IP for your home router, you can use UPnP and DDNS to your advantage. An end node will use UPnP to request your WiFi Router to open ad forward certain outward facing ports to it and then. It will then detect the global IP address of its parent's gateway (in your case, your own home router) and register it with its DDNS server. You can then use the URL assigned to the device to access it from anywhere in the world.

Use Virtual Private NetworkingPay for a virtual private networking service and use OpenVPN clients on your end devices and bring them all on the same LAN

Use yaler.netIts a paid reverse SSH relay service. Works well for SSH and HTTPS connections to your device

Use a server with a global IP addressRent virtual VM from digital ocean or amazon or google and develop software for your devices to send data to or receive data from. this is what most manufacturers do for their IoT appliances.

There is a 5th option if:

You are working on a DIY project - handful of embedded linux devices with SSH access.

Your devices are located in the same geographical area (i.e. within the same telecom circle)

Your devices have 3G/4G modem

The trick is to stick the same network operators SIM card in all your devices. All these devices will be assigned IP addresses on the same subnet and would be able to ping each other.

The 10.*.*.* only allows around 16 million unique IP addresses and so I have reason to believe that in India, different MNO circles would be on different logical LANs

Here are the results of my tests - I used two GL-MiFi with 4G modems in them with Reliance Jio 4G SIM cards. Both the devices were located within Maharashtra (one in Pune and other in Talegaon)

I opened the outward facing ports on GL-MiFi and deactivated the firewall on them.

I then conducted iperf tests and here is what I got. It seems that we can easily transfer data between the devices at around 1-2 Mbps while on the Jio network.

We all want our smartphone to charge quickly. And different phone manufacturers have either created their own propriety method of charging (Oppo VOOC or MediaTek PumpExpress+ or Motorola's TurboPower or OnePlus's Dash) or have opted to comply with a industry wide standard like Qualcomm's Quick Charge series of standards).
These technology work my allowing a phone to tell the charger to step up the voltage beyond 5 volts so that the power available to the phone for charging the battery is more than what a good 5 volt / 2 ampere wall/car charger can supply.

I have a Moto G4 plus and I wanted to make sure that I had access to fast charging at home/office, in car or while travelling. So I went ahead and got the following accessories

My Moto G4 plus along with the various charging accessories

Voltmeter

USB Voltmeter Stick

This small device is what allowed me to check at what voltage/current the various chargers were charging my phone or regular devices.

It has a USB male and female receptacle so that it can sit between the charger and the USB cable.

It shows the voltage, current as well total mAh consumed during the past few hours - all these 4 parameters are shown on its OLED display. It ofcourse discounts the current it itself requires.

A reset button will allow you to reset the energy and time counter - The energy and time counters are stored in its non volatile memory and their values are preserved across power cycles so you need to reset them manually.

Original TurboPower Charger that cam with your mobile phone

Wall Charger

Comes in the box when you buy your phone

There re two varieties of these chargers - one has a USB female socket in it and comes with a detachable microUSB cable while others have microUSB cable connected to it permanently. I have both of these but prefer the one with USB female socket

When I used the voltmeter to investigate the charger I discovered the following:

It charges regular devices at 5.0 volts

It charges Moto G4 plus and Moto G5s plus at around 9.0 volts

It charges Qualcomm QC 3.0 compatible devices at around 11.5 volts

Thankfully, its 2 pin has the correct diameter and distance between them to fit snugly in Indian AC main sockets - unlike those sad chargers which have europlugs which hang loosely when used with Indian sockets.

LCARE Qualcomm QC 3.0 Quick Charge Power Bank

Now that I had charger for fixed sockets (Car and AC Mains) I wanted a portable power bank with fast charging technology as well. Motorola's TurboPower seemed compatible with QC 2.0/3.0 so I tried this particular powerbank and was pleasantly surprised.

When I used the voltmeter to investigate the charger I discovered the following:

It charges regular devices at 5.0 volts

It charges Moto G4 plus and Moto G5s plus at around 9.0 volts

The QC 3.0 technology is used in input as well as output sides. i.e. when you try to charge the power bank itself using any of motorola's original accessory - the car charger and the wall charger - you notice that those chargers themselves are able to charge the powerbank at around 11.5 volts - so basically you have a power bank that not only charges other devices quickly, but also itself gets charged quickly.

A backlit LCD display shows the charge level remaining in percentage numbers and also shows the charging technology being used

One downside - the powerbank cannot charge mobile devices when it is itself being charged.

Sunday, January 7, 2018

Plastics! Cancer! Correlation!
And so we move away from plastic bottles to glass bottles.
But glass bottles pretty but fragile.
So what do we do?

We get food huggers!!!
Food huggers seemed onle somewhat useful to me all this while until now
The silicone rubber food huggers will protect the bottom of the bottles - I was worried that I might end up banging them on the floor when I have a sip in the middle of the night.

The food huggers come as a set of 4. Only the two larger ones have diameters large enough for the glass bottles linked to above. The smaller two won't fit.So if you get 6 bottles, you will need to order 3 sets of food huggers. Of the 12 pieces of food huggers, you will end up using only 6 of them.

Various sized food huggers seem to be colored differently to match the color of the vegetable/fruit they are supposed to protect. Yellow is for lemons, Purple for onions, Green for capsicum, Red for tomatoes. This is a good thing - food huggers come in various colors and so do the glass bottles. So there is a very high chance that you would end up getting matching cushions for each bottle except for the blue one.

These silicone rubber huggers can also be used for green tea flasks as well.

Also, here are some photos on how these huggers can protect half cut vegetables from drying up when left in the fridge.

Friday, January 5, 2018

If you are an IoT enthusiast who uses devices that run OpenWrt (routers from Goodlife, or MT7688), you would have considered creating a plugin for LuCI so that you can expose the functionality of any sensors/actuators that you may have connected to your OpenWrt box via OpenWrt's builtin web console.

This article on openwrt.org's wiki will tell you exactly how to do that.
As maybe obvious from the page, if you want to create dynamically generated web content, you will need to write lua scripts.

When trying out the steps from the wiki article for my GL-MiFi, I had to modify the file locations for placing various script like so:

new_tab.lua had to be placed in:/usr/lib/lua/luci/controller/myapp

cbi_tab.lua had to be placed in:/usr/lib/lua/luci/model/cbi/myapp-mymodule

cbi_file can be put in the same place as mentioned:/etc/config

view_tab.htm had to be placed in:/usr/lib/lua/luci/view/myapp-mymodule

Once I had the placed the files in the right location, I could see them in the web UI:

My next step is to modify the lua scripts to run executables in C to query the various sensors that I have connected to my OpenWrt devices and display the latest values within a tab in WebUI.

I use the device specifiy SDK from OpenWrt to compile my C programs into executables.

Later on I will package my lua scripts and C programs into a simple .ipkg packages that one can install on any OpenWrt device

Saturday, August 26, 2017

Here is a simple code for shared library (.so) and an executable that uses it:

Library Source files (libhello.c and libhello.h):

Source for the executable that uses the above library (main.c):

There are many ways to build and execute these sources. Lets look at three of them. The first one is a collection of manual commands that you need to execute in a particular order. The other two uses some form of build system. Before you proceed, make sure to have the C compiler installed on your Ubuntu PC. To do this, execute the following at the command prompt:

Thursday, July 13, 2017

I have owned a Black and Decker DP240 Cordless Electric Screwdriver for 5 years now. Its battery had started losing its capacity to hold charge, so I looked online to see if it was possible to change its batteries. I couldn't find any blog/DIY guide on which batteries to replace the internal ones with and how to go about pry open the screwdriver and putting it back. So here are some photos outlining how I changed the batteries in mine and turned it into new.

To open the screwdrive, you will need a set of "Torx Pin 6 lobe" screwdriver set. You cant use regular torx screwdriver bits. You need ones with holes in the center of the bits so that the center pin on the screw can fit into those holes. You can buy just a set of just the bits here.

Torx pin 6 lobe Screwdrivers to open the shell

Screwdriver with the shell opened

It seems that the screwdriver comes with two AA size1.2V NiCd 800 mAh cells installed

I replaced the 800mAh batteries with 2550 mAh NiMH cellseneloop by Panasonic is the best brand of NiMH cells