Category Archives: Technology

Battery-less switches: The next big thing in IoT ?

Internet of Things, or IoT as it is popularly known, needs no special introduction as it has been making rounds for quite a few years. As I am writing this, I know there are probably million other researchers in thousands of laboratories around the globe, sweating it out to come up with something new in this field. IoT relies on good quality sensor data at the right time in the right format, which is why energy harvesting wireless sensors are of special interest.

Imagine, being able to control your air-conditioner or television through a remote which doesn’t need a battery; yeah, you read that right. This is one of the many applications that energy harvesting switches can offer.

IoT

EnOcean, a Siemens spin-off, is a leading batteryless switch manufacturer with open APIs available for researchers to  play around and hook it up with other IoT devices. It uses a piezoelectric generator,  and the mere mechanical pressure generated by pushing the switch generates just enough electricity to transmit a unique switch code. Range of the switch comes in at around 120 meters which should give end-users plenty of flexibility. Two way communication is possible with EnOcean and the datarate comes around 125 kbps (For more info and comparison of EnOcean with other IoT technologies, refer to my paper here)

enocean

Refer to enocean website here for details on motion energy harvesting.

Today, energy harvesting wireless technology is very well established for providing M2M (Machine to Machine) solutions in the building automation sector, bridging the control of light, HVAC and other fields of building technology to smart home, smart metering and energy management systems. This is the starting point to actuate further applications that lead to the Internet of Things in the long term.

For hobbyists, hooking up a EnOcean switch to your home automation network is not a Herculean task. There are open source automation applications like OpenHab available which can do the task seamlessly.

References:
1. https://www.enocean.com/en/newsitem/energy-harvesting-wireless-and-iot/
2. https://www.enocean-alliance.org/en/enocean-technology-and-the-internet-of-things/
3. http://www.electronicsweekly.com/uncategorised/sensors-powered-by-energy-harvesting-key-to-iot-success-2015-08/
4. https://en.wikipedia.org/wiki/EnOcean

Reading data from multiple TelosB motes and pushing to MySQL Database

So, before starting the tutorial, I assume that you have installed TinyOS on your machine (whether it be Linux or Windows or MacOS). If not, follow this link. They have a really good step by step tutorial on how to do this.

1326546992_mote3

So, what I have is a set of TelosB motes (8 to be exact). 7 of them  placed in different parts of our laboratory, monitoring the climate data and the 8th one being used as a base station (a gateway, rather) connected to the central server machine. This Wireless Sensor Network, made of TelosB motes will be sending the climate (light, temperature, humidity) data to the base station in real-time and the base station in-turn pushes it to the MySQL database. There is provison to attach additional sensors to the TelosB motes. In my case, I have added  an additional microphone breakout board (ADMP401) to the TelosB motes which will send amplitude of sound (in dB) in addition to the climate data.

My database looks like this. The devices are identified by their device ids and corresponding data (whether temperature, light, humidity or whatever) being identified by a task number.

DB

The data can be represented in a meaningful way, by means of a real time dynamic chart using Java, JDBC and JSP/HTML5. This is beyond the scope of this tutorial and therefore I am not going into the details.

 So, how did i do this? Here it goes.

Steps

Note: All the programming was done in Linux platform, and using the Eclipse IDE. (Kepler Version)

1. Start by programming one of your motes with the BaseStation app which is already coming with the TinyOS package. Open the terminal/Cygwin and navigate to BaseStation folder. Type motelist to ensure that the mote is attached to the machine. If it displays “No Devices Found”, unplug and plug the mote again.

cd BaseStation
cd src
make telosb
make telosb install,1

This will compile and install the application onto the mote. Note that the id assigned to the device can be anything (1 in my case). It is just used to identify a particular device.

2. Now that the gateway is ready to receive messages, we should program the other motes with nesC code that will transmit the data to the base station mote. The oscilloscope application present inside the package can be edited for this purpose.

Edit OscilloscopeC.nc file which can read and transmit 5 different data sets. Initialise reading variables for all the 5 sensors.

oscilloscope_t local;
oscilloscope_t localL;
oscilloscope_t localH;
oscilloscope_t localP;
oscilloscope_t localM;

uint8_t reading;
uint8_t readingL;
uint8_t readingH;
uint8_t readingP;
uint8_t readingM;

interface AMSend as AM1;interface AMSend as AM2;
interface AMSend as AM3;interface AMSend as AM4;
interface AMSend as AM5;

Similarly add 5 Receive, Timer and Read interfaces.

Example functions are given below. (Complete code is not given. Spend some time on the already available Oscilloscope app and the functions listed here, and you will get the hang of it 🙂 )
Replicate the fired(), readDone(), sendDone() and receive() functions for all the 5 sensors.

event void T1.fired() {

local.id=81;
if ((reading == NREADINGS) )
{
if (!sendBusy && sizeof local <= call AM1.maxPayloadLength())
{
memcpy(call AM1.getPayload(&sendBuf, sizeof(local)), &local, sizeof local);
if (call AM1.send(AM_BROADCAST_ADDR, &sendBuf, sizeof local) == SUCCESS)
sendBusy = TRUE;
}
if (!sendBusy)
report_problem();

reading = 0;
/* Part 2 of cheap “time sync”: increment our count if we didn’t
jump ahead. */
if (!suppressCountChange)
local.count++;
suppressCountChange = FALSE;
}
if (call Read.read() != SUCCESS)
report_problem();
}

event void Read.readDone(error_t result, uint16_t data) {

if (result != SUCCESS)
{
data = 0xffff;
report_problem();
}
if (reading < NREADINGS)
local.readings[reading++] = data;

call T2.startOneShot(localL.interval);
}

event message_t* R1.receive(message_t* msg, void* payload, uint8_t len) {
oscilloscope_t *omsg = payload;
report_received();

if (omsg->version > local.version)
{
local.version = omsg->version;
local.interval = omsg->interval;

startTimer();
}

if (omsg->count > local.count)
{
local.count = omsg->count;
suppressCountChange = TRUE;
}

return msg;
}

3. Edit the already available OscilloscopeAppC file to map the different sensors

OscilloscopeC.AM1 -> AMSenderC;
.
.
OscilloscopeC.AM5 -> AMSenderC;

OscilloscopeC.R1 -> AMReceiverC;
.
.
OscilloscopeC.R5 -> AMReceiverC;

OscilloscopeC.T1 -> TimerMilliC;
.
.
OscilloscopeC.T5 ->TimerMilliC;
OscilloscopeC.ReadL -> PhotoSensor;
.
.
OscilloscopeC.ReadM -> Microphone;

4. Next, you need to add the database configuration details in Oscilloscope.java file

static String userid=”…”, password=”…”;
static String url = “jdbc:mysql://…….”;
static Connection con = null;
static Statement stmt = null;
con = DriverManager.getConnection(url, userid, password);
Inside the public synchronized void messageReceived(int dest_addr,
Message msg) function,  write the syntax for pushing the data to the MySQL database. For example, in my case it looked something like this:

statement.executeUpdate(“insert into solar_data ” + “values  (‘”+((omsg.get_id())%10)+”‘,'”+firstDigit(omsg.get_id())+”‘,'”+reading+”‘,'”+currentTime+”‘)”);

Repeat this for all parameters (Light, Temp, Humidity etc) by filtering them using if else blocks.

The delay interval can also be included.

And that’s it. Connect your base station TelosB to usb port. Ensure that it is detected by typing “motelist” in the terminal. Go to the java folder, make and run the app. Your motes should automatically be detected and shown in the Oscilloscope application. Basic graphs will be generated here and the data will be pushed to the MySQL database too.

Voila! You may choose to make responsive graphs using the generated data in HTML5, AngularJS etc.

Have fun exploring. Until next time.

 

Remote /Cloud Air Conditioner Control using Arduino, Bluetooth and J2EE

So, we have this very old air conditioner in our lab with a wired thermostat, which basically works alright but doesn’t have a remote control. The air conditioner is so old that the spare parts of this system are not even available in the market right now. As part of making everything “futuristic”, we decided to do little tweaking to enable wireless cum cloud control for this thingy.

The initial step was to check how the system works. The thermostat is DC powered and have its own proprietary protocol for sending commands and signals to the machine. Examining the terminals of the ON/OFF switch with a multimeter revealed that shorting the terminals for a few seconds would send the ON/OFF signal to the system. And I guess, this is how most of the thermostats, irrespective of the brand, do the job.

Now that we know how to turn ON/OFF the system, time to gather the hardware. Do reverse engineering, what needs to be at the end of the system is a Relay, which can do the “shorting”. And what can power the relay? A 5V signal. And where should it come from? From an output pin of Arduino. And what should trigger the signal? A command from PC/Mobile/Tablet. And how should the command be transmitted. Via Bluetooth/Zigbee/Wi-Fi. Here we use Bluetooth, because the hardware is comparatively cheap, and it can be easily integrated with Arduino. So here it goes, the complete hardware and software list for making this system.

1. Arduino (Can be any. Here I use Uno)
2. Bluetooth Adapter for Arduino HC-05 or HC-06
3. 5V Relay
4. Wires and Jumpers
5. Breadboard/ Soldering Board
6. Arduino Programming Software
7. Eclipse IDE where we run the Dynamic Java Application for web interface.
8. Serial Terminal for Windows, For Example TeraTerm
9. Bluetooth Serial Terminal Software for Android (Optional)
10. And obviously the thermostat connected to AC and a little bit of patience 😉

Start by wiring the HC-06 to the Arduino. Connect the TX pin of HC-06 to the RX pin of Arduino. Connect the RX pin of HC-06 to the TX pin of Arduino through a voltage divider. Connect Vcc(5V) and GND pins of HC-06 to respective terminals (Refer figure).

Take the output from any of the Arduino digital pins. In my case, I used pin number 10 (Of Arduino Uno). This output is connected to one of the the energizing coil terminals of the relay. And the other pin is connected to the GND. The outputs of the relay are connected across the ON/OFF terminals of thermostat.

IMAG0577_1

Time to program the Arduino. Set the pin 10 as output and make it LOW and HIGH with a delay of 1 second. Why because the shorting has to persist for a second for the thermostat to turn ON. Do the same thing for turn OFF process as well. During programming, make sure you disconnect the HC-06 from Arduino.

char VAL;
int AC = 10;
void setup() {
Serial.begin(9600);
pinMode(AC, OUTPUT);
}
void loop() {
Serial.println(“AC CONTROL \n”);
Serial.println(“Press 1 to turn ON or 0 to turn OFF”);
while (!Serial.available());
VAL = Serial.read();
if(VAL == ‘0’ ) {
digitalWrite(AC, LOW);
}
if( VAL == ‘1’ ) {
digitalWrite(AC, HIGH);
delay(1000);
}
delay(50);
}Now that the entire hardware setup is ready, we should check if this really works. Pair your laptop or PC with the HC-06 (Obviously, your machine should have Bluetooth. Use a Bluetooth adapter, if it is not available inbuilt). The password should most likely be “1234”. Open a serial terminal, for eg TeraTerm. Connect to the respective COM port. Type “1” to see if the relay is working. You can also use Bluetooth Serial Terminal for Android to check.

To enable local control using a web application, we should make a dynamic Java application and run it on a local server. Import RxSerial and RxParallel libraries for Java. Open the respective COM port, set the Baud Rate to send the commands. For the front-end, use JSP-JSF or HTML-5 to create a simple web page. Note that for cloud control, the program should be written in such a way that the web app should send a signal to the local machine which is connected to the HC-06 via Bluetooth. This signal should trigger opening the COM port on our local machine.

Export this application as a WAR file and upload to cloud server. The cloud server should support JSP-JSF /HTML and should also have an application server like Apache Tomcat. Do note that the local web application and the server should be running the same version of the Web Server; Tomcat or JBOSS or whatever. Otherwise, there might be problems launching the application from Web.

IMAG0579_1

You could also make an Android application to do the control from mobile or tablet. Bluetooth Terminal Apps are available though, as I already mentioned.

That’s it. Restart your application server after deploying the web application. And voila!! You can control your AC from web. Further modifications like temperature control, auto scheduling ON/OFF can be done easily. But yeah, once you are done with the basic stuff, you can always build on top of it. 🙂

Ciao!

Rahul Ashok