How to create ambient notifications with Python and a smart bulb

Ever since mentioning my latest little coding project on the IoT Podcast, I’ve heard from a number of folks asking me how I did it.

In case you missed it, I have a small Python app that checks the percentage gain or loss of a cryptocoin every two minutes and sends that data to a connected bulb in my office. The bulb is lit either green to show a gain or red to show a loss. The bulb’s brightness is set to the percentage number gained or lost. A bright green light is a good thing is this case. A brightness percentage change of just one or two percent isn’t much but these coins can fluctuate wildly in price; I’ve seen 50 percent changes in just a few hours at times. In those cases, the brightness indicator is very noticable.

Here’s a short video look during the early stages of the project:

While the use case for my project is very specific, the general concept can be tailored to whatever information you want. For example, if you wanted to know the number of degrees above or below 70 it is outside, you could program a light to be a color representing warmth, such as yellow or orange. So consider this code a basic framework for your own project.

All you need is a both a data source and smart bulb that has a public API available. In my case, I’m getting my data through the Binance API because Binance is the coin exchange I trade on. For the bulb, I’m using the LiFX API that supports my LiFX bulb. The latter is great for basic testing: There’s a web interface to programmatically control your LiFX bulb without any coding involved.

Below is an early, simple version of my Python code as I started: At this point it didn’t light the bulb red to represent a percentage loss. I’ve since added that and other functionality. I’ve also made the code more modular since then, but since it gets pretty specific to my use case, I’m sharing the basic early version as an example that you can build upon for other purposes. Note that I’m a coding n00b so this first version isn’t the most efficient method by any means; I simply wanted to get the base functionality working before splitting the code into reusable functions and such.

To easily send http requests via the APIs, I’m importing the Requests package. I also import the Threading package to allow the code to run repeatedly; in this case, it’s every 120 seconds as shown on line 8.

Using code to programmatically control the LiFX bulb requires an ID token for security purposes. I’ve masked mine in the above image. You can generate a token in your LifX account settings as noted in the API. Lines 16 and 17 are the base URLs for both APIs, which are needed to generate http commands for gathering (or getting) Binance data and changing (or putting) the state of a LiFX bulb.

Next, I’ve set some parameters needed for the http requests the code sends. On line 20, I’ve set a variable for the bulb color in the case of a gain. Remember, this is an early version of the code, so I later set one to represent red for a “loss color”. Line 21 is the symbol for the coin I want to track: In this case, it’s XRP for Ripple coins, but I can set it for any coin on the Binance exchange.

Line 27 generates the http request URL to query the Binance site and it returns coin data in JSON format, which is set to the variable named “data” in line 30. From there, the code looks for the “priceChangePercent” returned in the JSON data and stores it in the variable “percentage”. I now have the percentage gain or loss for my coin.

Next the program uses that data to light the bulb. Here’s a look at the parameters you attach to the base LiFX API URL for doing this with an http request.

Since the LifX API says brightness is a number between 0 and 1, line 35 formats the percentage appropriately and saves that number to a “brightness” variable. The next line creates some parameters to pass over to LiFX, such as the power state, the brightness and the color. And line 38 adds those parameters to the base LiFX URL to change a bulb’s state; once that request is sent to LiFX, the bulb reacts appropriately. That’s it! And every two minutes the process repeats the coin data request followed by any adjustment to the bulb.

Again, this code is specific to my purposes, but you could tweak it by pulling in different data from other sites or use different smart bulbs, provided they have a public API. Now that I have some base functionality, I plan to expand it by illuminating the light to represent my total portfolio gain or loss; that’s trickier because it requires an encrypted account parameter in the http request and I’m still working on that in my code.

I’d also like to rework this project with a set of Nanoleaf light panels instead of a single bulb. That way, I can show more granular data because I have more lights to work with. Regardless, it’s not that difficult to get devices in your smart home telling you information at a glance, so have fun!

 

Stacey on IoT | Internet of Things news and analysis

Researchers determine ways to connect IoT sensors via ambient waves

Who needs radio communications? IoT sensors could connect via ambient waves getting rid of the radios altogether, according to a new study from Disney Research.

A team of researchers, led by associate lab director and leader of Disney Research’s Wireless Systems group Alanson Sample, devised an ultra-low-power system of sensors that transmit data to a central receiver by reflecting the ambient radio waves from commercial broadcasting systems that already bathe most office environments.

The idea is to reuse the all radio signals around as a medium to transmit data, said Sample.

Since it is the generation of radio waves that consumes most of their battery power, this approach radically reduces the power requirements of the sensor nodes. In a demonstration, the researchers met the tiny bit of remaining power demand by using solar cells optimized for low-light conditions.

The details of the researchers’ ultra-wideband (UWB) ambient backscatter system was presented at the IEEE Conference on Computer Communication, INFOCOM 2017, demonstrating the system using ambient signals from 14 radio towers along with two mobile phones in an indoor environment.

TV station is a system which is a single source that requires less power by using ambient waves. But the range is limited until the power of ambient signals is boosted to high levels.

According to Sample, UWB approach, which backscatters all ambient sources, offers key advantages. Multiple backscatter channels boosts signal-to-noise ratio, substantially improving the sensitivity of the backscatter reader and decreasing dead zones. This enables the system to operate on real-world ambient sources and substantially extends the range to 22 metres when using ambient signals from broadcast towers and 50 metres when using ambient signals generated by mobile phone up-link traffic.

iottechnews.com: Latest from the homepage

Disney Research showcases how ambient radio waves could power IoT devices

Disney Research’s Wireless Systems group demonstrates IoT technology powered by radio waves.

Radio waves are used by many IoT devices to connect to the wider internet and send back data, but this process often uses a lot of energy. Researchers at Disney Research, the R&D arm of The Walt Disney Company, have come up with a way for devices to use ambient radio waves to send data.

Alanson Sample, associate lab director and leader of Disney Research’s Wireless Systems group, has devised an ultra-low-power system of sensors that transmit data to a central receiver by reflecting the ambient radio waves from commercial broadcasting systems that already bathe most office environments.

“Our idea is to reuse all the radio signals that are around us as a medium for transmitting data, much like sending ripples across a pond,” Sample said.

Read more: Purdue researcher develops technology powered by body heat

Power requirements

This substantially lowers the power requirements of sensor nodes, because it is the generation of radio waves that consumes most of their battery power. The researchers revealed that they could meet the tiny bit of power demand that remained by using solar cells optimised for low-light conditions.

They demonstrated their ultra-wideband (UWB) ambient backscatter system in an indoor office environment, using ambient signals from 14 radio towers, as well as two mobile phones.

Backscatter communication is already used in passive RFID tags. In that case, a RFID reader transmits radio frequency power to the battery-free RFID tag; the tag sends data to the reader by reflecting, or backscattering, the carrier wave back to the reader. These systems have limited range, however, which makes them impractical for some IoT systems.

Other researchers have shown systems that require even less power by using ambient radio waves from a single source, such as a TV station. But, again, the range is limited to a few meters unless the power of the ambient signals is boosted to high levels.

Read more: Greentomatocars joins IoT network mapping air pollution in London

Ultra-wideband backscatter

Sample said that using ultra-wideband, which backscatters all ambient sources, has some advantages. Using multiple backscatter channels boosts the signal-to-noise ratio, substantially improving the sensitivity of the backscatter reader and decreasing dead zones.

He added that this enables the system to operate on real-world ambient sources and substantially extends the range – up to 22 metres when using ambient signals from broadcast towers, and 50 metres when using ambient signals generated by mobile phone uplink traffic.

He added that the nodes are simple and require the backscatter reader to do the heavy lifting for the system. The reader must receive the backscatter signals, decode and combine multiple backscatter carriers to recover the data from each sensor. The reader uses four software-defined radio receivers – one for the FM radio band, another to cover most of the cellular uplink and downlink bands, and two for digital TV bands.

The hardware doesn’t need to be tuned to any frequency band and thus such devices can be used in almost any metropolitan area. Unlike other experimental systems that leverage ambient radio waves, the Disney system doesn’t focus on a single-signal source, but uses all available ambient radio sources, from FM radio broadcasts to digital TV signals to transmissions to and from cellular phones.

More information on the research, conducted by a team at Disney Research’s Pittsburgh lab, can be found here.

The post Disney Research showcases how ambient radio waves could power IoT devices appeared first on Internet of Business.

Internet of Business