Archive

Posts Tagged ‘power’

How to Build and Flash ESPurna Open Source Firmware to Sonoff POW Wireless Switch

December 3rd, 2016 10 comments

ITEAD Studio Sonoff family is comprised of various inexpensive ESP8266 WiFi power switch, and the company sent me two of their latest CE certified models with Sonoff TH16 + external temperature & humidity probe, and Sonoff POW to measure power consumption. I checked the hardware is the first part of the review, and used Sonoff TH16 to control a water pump with the stock firmware and Ewelink Android app in the second part. It works reasonably well, but it relies on the cloud, so if you lose your Internet connection or the service closed, you can’t control the relay manually anymore. Luckily, the UART pins are exposed on Sonoff switches so you can solder a 4-pin header and connect a USB to TTL to flash your own firmware.

Click to Enlarge

Click to Enlarge

Please don’t connect Sonoff devices to the mains when programming them, it’s very dangerous, instead the USB to TTL board will power the system, and will allow you to program the board safely. Later you’ll be able to update the firmware, if needed, over the network.

The next step is to select the firmware you want to use, and I’ve been advised two firmware for ESP8266, namely ESPurna specifically designed for Sonoff devices, and ESPEasy with a larger community of users. The latter may be usable to control the relay, but it has yet to support HLW8012 chip used to measure power consumption in Sonoff POW, so I decided to go with ESPurna.

That’s the description of the firmware from its bitbucket page:

ESPurna (“spark” in Catalan) is a custom C firmware for ESP8266 based smart switches. It was originally developed with the ITead Sonoff in mind. Features:

  • Asynchronous WebServer for configuration and simple relay toggle with basic authentication
  • Communication between webserver and webclient via websockets with secure ticket check
  • Flashing firmware Over-The-Air (OTA)
  • Up to 3 configurable WIFI networks, connects to the strongest signal
  • MQTT support with configurable host and topic
  • Manual switch ON/OFF with button (single click the button)
  • AP mode backup (double click the button)
  • Manual reeset the board (long click the button)
  • Visual status of the connection via the LED
  • Alexa integration (Amazon Echo or Dot) by emulating a Belkin WeMo switch
  • Support for automatic over-the-air updates through the NoFUSS Library
  • Support for DHT22 sensors
  • Support for the HLW8012 power sensor present in the Sonoff POW
  • Support for current monitoring through the EmonLiteESP Library using a non-intrusive current sensor (requires some hacking)
  • Command line configuration

I could not find firmware release for ESPurna, but Xose Pérez – the developer – has provided some basic instructions to build and flash the firmware to Sonoff. Those are not really detailed however, and it took me nearly a full day to successfully build and flash the firmware to Sonoff POW, mostly because I was not quite familiar with most of the tools used. So I’ve reproduced the step I went through in Ubuntu 16.04, and hopefully this can help people getting things done more quickly.

Let’s retrieve the source code, and enter the code directory first:

You can build the project with PlatformIO or the Arduino IDE. The instructions are for PlatformIO so that’s what I used. There are two ways to build the code with the project wither using Platform IDE for Atom and the command line, or simply using the command line. With insights, I ended up using the command line, but I’ll show both methods.

Setup PlatformIO IDE for Atom to build ESPurna

First, you’ll need to download PlatformIO IDE for Atom for your operating systems, and install it. For Ubuntu 16.04, I selected “Download .deb” for Linux and installed it through through Ubuntu Software program. Alternatively, after download, you can install it from the command line:

You can now start Atom program in Ubuntu dash, select Open Project, and browse for espurna/code directory to load the project we’ve just gotten from Bitbucket.

Click to Enlarge

Click to Enlarge

The tick button on the top left corner is to build the project, and the right button just under is to upload the firmware to the target board. But if we try to build the firmware now it will fail with an error about “espressif8266_stage”. That’s because we need to install Espressif 8266 (Stage) development platform. First we need to enable Developer mode in the IDE by going to the top menu to select PlatformIO->Settings->PlatformIO IDE, and checking “Use development version of PlatformIO“.

platformio_core_enable_development_version

Click to Enlarge

Now install PlatformIO shell commands from either a system Terminal, or PlatformIO IDE terminal (PlatformIO->Terminal->New Terminal):

and finally install ESP8266 development platform:

At this point you can click on the tick icon to build the default “node-debug” environment, a build output window will show in the IDE, and quickly disappear if the build is successful.

Setup PlatformIO via Command Line to Build ESPurna

If instead we want to use the command line we can install the latest pip version, the developer version of PlatformIO, and the staging version of ESP8266 development platform:

You can check the build environment is set properly by running the following command in espurna/code directory:

It will automatically download, build and install all dependencies and build for “node-debug” firmware for NodeMCU board. If it is successful, it will end as follows:

So I find the command line option much more easy and straightforward.

Build ESPurna for Sonoff POW

However, we are not using NodeMCU board here, but Sonoff POW, and there are two environments defined just for that:

  • sonoff-pow-debug – Build firmware to flash over serial
  • sonoff-pow-debug-ota – Build OTA firmware to upgrade the firmware over the network

The parameters for each environment are all defined in platformio.ini. First we need to build sonoff-pow-debug environment:

But it failed with an error message related to hlw8012 library:

I reported the issue on Bitbucket, but the main developer could not reproduce the issue. Eventually I found out that it could be a PlatformIO bug, as the system does not recursively checking for includes outside of main.ino. So I added <hlw8012.h> in the main.ino as follows:

and the build could complete:

Since we’ve already changed the code, you may also consider changing “#define ADMIN_PASS  fibonacci” in code/src/config/general.h to use a different default password. The password can also be changed in the web interface, but this makes sure you won’t have a device somewhere with the default password common to most users.

Flashing Firmware to Sonoff POW

Now that we’ve made sure the firmware could build, it’s time to flash it to the device.

First we need to setup some udev rules to allow flashing over serial:

Now connect the USB to TTL to a USB port on your computer, press the button (connected to GPIO0) on Sonoff POW for several seconds until both LEDs are off to make sure you are in bootloader mode, and start flashing with:

Success! Great. If you have your own firmware to flash it may be useful to know the actual command used to flash the firmware was:

Building and Flashing the ESPurna filesystem

Wait! We’ve just flashed the firmware, isn’t it all? Nope, as the webserver files are stored in another partitions, and compressed in a single index.html.gz file for better performance. The exact reasons why are further explained here.

We’ll need Node.js and gulp command line client:

Now inside espurna/code folder , we can check if building the file systems works with two commands:

Here my successful gulp attempt:

Finally, we can run the following (which also runs the two commands above) to flash the file system to the board, after entering bootloader mode by pressing the button:

Now that’s done.

A Quick look at ESPurna Web Interface

ESPurna firmware and filesystem has now been flashed to Sonoff POW. But does it work?

Click to Enlarge

Click to Enlarge

I can see a new SONOFF_POW_XXXXX access point, so that does look good. I can connect using the default password “fibonacci”, then go to my web browser to access http://192.168.4.1, and login again with admin/fibonacci credentials.

Click to Enlarge

Click to Enlarge

ESPURNA 1.03 interface goes to the status menu first, and there I can turn on and off the relay remotely, and check the power consumption in watts, which remains at 0 watt since I have not connected it to the mains yet. It’s also possible to turn the relay on and off with the button, and there an option to select whether to turn on or off the relay at boot time, which is great since I need it on at all times.

The web interface also allows you to change general parameters including the hostname and password, as well as enable or disable the HTTP API (disabled by default). The WiFi section is used to connect to up to 3 wireless routers, the MQTT section lets you configure an MQTT (Mosquito) broker, and the power section is used to calibrate the power monitoring device.

If you just intend to check the current power consumption and turn on and off the switch with your phone, you don’t have to do anything else. But I’d like to find some ways to draw daily, weekly, monthly charts of my office power consumption using either MQTT or the HTTP API. I’ll have to study how to do that, and that will hopefully be the topic of my next post about Sonoff POW.

Sonoff POW can be purchased on ITEAD Studio for $10.50 plus shipping, but is currently out of stock with the company manufacturing a third batch soon.

This Video Shows Vulkan API’s Higher Power Efficiency Compared to OpenGL ES API on ARM SoCs

October 20th, 2016 1 comment

Vulkan was introduced as the successor of OpenGL ES in March 2015, promising to take less CPU resources, and support multiple command buffers that can be created in parallel and distributed over several cores, at the cost of slightly more complex application programming since less software work in done inside the GPU drivers themselves with app developers needing to handle memory allocation and thread management.

opengl-es-vs-vulkanThis was just a standard at the time, so it still needed some time to implement Vulkan, and work is still in program but ARM showcased the power efficiency of Vulkan over OpenGL ES in the video embedded at the end of this post.

The demo has the same graphics details and performance using both OpenGL ES and Vulkan, but since the load on the CPU in that demo can be distributed over several CPU cores with Vulkan against a single core for OpenGL ES, it’s possible to use low power cores (e.g. Cortex A53) operating at a lower frequency and voltage, hence reducing power consumption.

ARM also measured that the complete OpenGL ES demo would use 1270 joules against 1123 Joules for the Vulkan demo, resulting in about 15% energy savings in this “early stage” demo.

Categories: Android, Video Tags: gpu, opengl, power, vulkan

Sonoff Pow is a $10.50 ESP8266 WiFi Relay Box that also Measures Power Consumption

October 10th, 2016 20 comments

In a recent article about Sonoff TH10/TH16 WiFi relays with sensor probes support, we also saw that ITEAD Studio started to have a nice family of home automation products. The company has now added one more item to the Sonoff family with Sonoff Pow support up to 16A/3500W input, and the first to also include power consumption measurements.

sonoff_powSonoff Pow specifications:

  • SoC – Espressif ESP8266 Tensila L106 32-bit MCU up to 80/160 MHz with WiFi
  • Connectivity – 802.11 b/g/n WiFi with WPA/WPA2 support
  • Relay – HF152F-T relay with 90 to 250 VAC input, up to 16A (3500 Watts)
  • Terminals – 6 terminal for mains and load’s ground, live and neutral signals.
  • Programming – Unpopulated 4-pin header for flashing external firmware
  • Misc – LEDs for power and WiFi status, power consumption circuitry with 1% accuracy.
  • Dimensions – 114 x 52 x 32mm
  • Temperature range – -40 ℃ to 125 ℃

sonff-esp8266-power-consumptionThe wireless relay can be controlled using Ewelink app for Android or iOS. But beside manually turning on and off the device, or settings timer like with all other Sonoff devices, you can also check real-time, daily or monthly power usage.

sonoff-pow-android-app

There’s some limited info on the Wiki,  and I could not find any API incase you want to measure the power consumption from your own app or program. But at least they’ve release the schematics showing HLW8012 chip (Datasheet in Chinese)  is used to measure power consumption, and is connected to ESP8266 via SCL and PWM1 pins. The 4-pin header would also allow you to flash you own firmware relatively easily on the board.

The company also mentions “this is a customizable product. Based on the original prototype, we can make the customized prototype that meets your requirements”, so if you order in quantities you should be able to get a slightly modified hardware and customized firmware.

ITEAD Studio home automation products used not to have any kind of CE/FCC/UL/TUV/ETL certifications, but the company recently got CE certification for their Sonoff switch, which explains the CE logo on the unit.

Sonoff Pow is available now for $10.50 plus shipping.

Thanks to Harley for the tip.

Broadlink MP1 is a $20 WiFi Power Strip with 4 Independent Sockets

August 29th, 2016 20 comments

There are plenty of WiFi sockets going around such as Broadlink SP2 or Kankun KK-SP3, but in some cases it might be both more convenient and cheaper to get a WiFi power strip, and Broadlink MP1 offers just that with 4 sockets that can be controlled and programmed (timer) independently, and sold for just $19.88 on Banggood.

Broadlink_MP1Broadlink MP1 specifications:

  • Connectivity – 802.11b/g/n WiFi, controllable over 3G/4G with smartphone
  • 4 multi-standard (EU/US/AU, but not UK) sockets
  • Power input – 10A/250V (max)
  • Power output – 10A/250V (max)
  • Rated power – 2000W Total
  • Misc – Power button
  • Dimensions –  254mm x 60mm x 32mm; 50cm sockets spacing; cord Length – 1.5m with AU plug (Adapter provided for other countries)
  • Weight – 450g

The power strip can be controlled via Broadlink ihc (Intelligent Hone Control) app available for Android and iOS, which lets you independently manually turn on or off or set timers for each sockets. You can also use IFTTT to control the sockets, but it may require Broadlink SC1 “housekeeper”.  There does not seem to be an easy way to control the power strip with a computer.

Broadlink_Android-iOS_App

The strip is also sold for around $25 and up on Aliexpress, GeekBuying and GearBest [Update: Now $19.78 promo]. It’s been around for a few months already, but I have not found any hacks yet, and could not find the processor used in the strip. However I know it’s likely not running OpenWrt and there’s no SSH access. Reading further, I did find another model, Broadlink MP2, with 3 power sockets, and 3 USB ports that’s said to be based on a Mediatek solution, and sold for $27.59.

More information can be found on Broadlink MP1 and MP2 pages (in Chinese only).

The USB Type-C Authentication Specification Aims to Prevent Damage from Non-Compliant Cables and Adapters

April 13th, 2016 2 comments

The new USB Type-C standard is great, as cables are reversible so it does not matter if you connect them up or down, it can handle USB 3.1 data speed, as well as carrying video and up to 100W power thanks to USB-C power delivery. In theory all is great, but in practice, many USB-C cables are not compliant, and Benson Leung, a Google employee, has found that many USB-C cable sold on Amazon were not compliant, with even one damaging his Pixel 2 laptop and two USB PD analyzers.

His reviews on Amazon, as well as customer complaints, probably lead the company to ban the sale of non-compliant cable or adapter, but to really mitigate the issue, a technical solution was needed, and that’s why the USB 3.0 Promoter Group has defined the Authentication Protocol for USB Type-C as part of the USB Power Delivery 3.0 specifications.

USB-C_Authentication

 

Key characteristics of the USB Type-C Authentication solution include:

  • A standard protocol for authenticating certified USB Type-C chargers, devices, cables and power sources
  • Support for authenticating over either USB data bus or USB Power Delivery communications channels
  • Products that use the authentication protocol retain control over the security policies to be implemented and enforced
  • Relies on 128-bit security for all cryptographic methods
  • Specification references existing internationally-accepted cryptographic methods for certificate format, digital signing, hash and random number generation

Authentication will check the capabilities and certification status, before transferring user data and power. This will also prevent malicious embedded software or hardware to exploit a connection.

At least that’s the plan. I understand existing devices with USB-C port will be able to get a firmware update to support USB-C authentication, but obviously many devices will never be updated, so in the meantime you’ll have to be cautious, and one way to protect your devices from bad USB-C cables or adapters is to purchase one from Benson Leung Amazon list, which he has personally tested.

Via Liliputing and Arstechnica.

Categories: Hardware Tags: power, standard, usb

Henes Broon T870 is a Kids’ Electric Car Controlled by an Android Tablet

February 11th, 2016 No comments

If you ever wanted to played around with an electric car that’s a bit better than an RC toy, but don’t quite have the cash for a full-size Tesla model, Henes has designed an electric card for you your younger kids that’s controlled by an Android tablet and allows both manual and remote driving.
Henes_Broon_T870Henes Broon T870 specifications:

  • Tablet – 7″ Android 4.4.2 tablet PC smart system with HD resolution display, micro SD, HDMI and audio output
  • ARM Cortex-M3 based main control system
  • Bluetooth remote control
  • Built-in stereo speakers
  • Functioning hood & doors
  • 4 wheel drive with high density urethane tires
  • Spring suspension & shock absorbers
  • Leather bucket seat and seat belt
  • Foot pedal accelerator
  • Bright Headlight / Aux Light / Turn Signal Light / Tail/Brake/BackUp Lights
  • Motors – Dual 24V driving motors
  • Battery – Rechargeable 24V 7Ah battery pack for a little over 2 hours drive, or up to 20 km.
  • Dimensions – 134 x 73 x  63.5 cm
  • Weight- N/A

The car can reach up to 8 km/h, with a maximum sit capacity of 35 kilograms. The company recommends parents to use the remote control for kids between 1.5 and 3 years old, and let them drive themselves up to 5 year old or more (subject to height & weight).

Android_Tablet_Electric_Car_Dashboard

The tablet shows a dashboard like on “adult’s cars” with a tachometer, and a better level indicator. You can also adjust the lights, brake modes, adjust the speed level, play music, set remote control mode, and more. The promo video does not show much about the tablet, but shows a little how the car can be used.

Henes Broon T870 sells for $1,275 on Amazon US, and more information can also be found on Hemes Emporium website.

Via AndroidPC.es

BayLibre ACME Cape for BeagleBone Black Measures Power and Temperature with Sigrok

February 1st, 2016 No comments

Sigrok open source signal analysis software suite had a major release last week-end with libsigrok 0.4.0, libsigrokdecode 0.4.0, sigrok-cli 0.6.0, and PulseView 0.3.0. The new version added numerous bug fixes for supported hardware such as UNI-T UT61E digital multimeter or USBee AX Pro logic analyzer, and added support for several logic analyzers, oscilloscopes, multimeters, programmable power supplies, an electronic load, an LCR meter, a scale, and one BeagleBone Black cape, namely BayLibre ACME.

Click to Enlarge

Click to Enlarge

The ACME initiative was launched in order to get rid of the limitations of proprietary solutions, and provide an open source hardware and software multi-channel power and temperature measurements solution to the community.

BayLibre ACME cape supports up to 8 probes to measure VBUS (0 to +36V), VSHUNT ( 2.5uV up to 81.92mV), CURRENT AND POWER. Three current / power probes have been developed with all featuring TI INA226 for the ADC conversion:

  • ACME HE10 Power Probe
    • 6-pin HE10 header with up to 6A max current, 13mΩ contact resistance
    • 3 possible current ranges:
      • 0.005Ω for 1.5A < Current < 10A
      • 0.05Ω for 150mA < Current < 1.5A
      • 0.5Ω for 0 < Current < 150mA
  • USB Power Probe
    • Power Control – Power switching capability  through TPS22929
    • High precision resistor – 0.08Ω for Current up to 1A
  • Jack Power Probe
    • Power Control – Power switching capability  through TPS22929; 6A current limitation;20.5V transil for voltage protection
    • High precision resistor – 0.01Ω for Current up to 6A

There’s no much details about the temperature probe except it’s based on Texas Instruments TMP435 temperature sensor.

Click to Enlarge

Click to Enlarge

A custom Buildroot BBB Linux distribution is available with upstream ACME HW drivers, Sigrok software Suite, and low-level hardware interface interface. You can check the measured data on the command line, or a graphical user interface (PulseView) via HDMI or vncviewer. The solution also works with Xoscope digital oscilloscope application. You can find more technical details on BayLibre ACME Wiki and Sigrok Wiki.

ACME cape and the probes are said to be available now, but for some reasons you need to contact them via the form at the end of BayLibre ACME page in order to purchase them.

ACS712 Module Measures Currents up to 30A for as Low as $1 Shipped

January 23rd, 2016 7 comments

Usually, if I buy a high power electric appliance, I like to double check it power consumption either with a Kill-a-watt when possible, and when not, e.g. cable directly hooked to the device or current intensity is too high, I use a digital electric clamp meter. Both methods are quite convenient as you don’t need to cut any wire to measure the current and determine the power consumption, but they don’t allow for data gathering since they don’t connect to the network. Earlier this week, I’ve come across a projects using ESP8266 for a mains energy monitor for a solar panel setup, and measuring mains current, electric meter, and gas meter. They use a photosensor to measure power consumption on their electric meter, which works, but may be problematic if the meter is on the street, and iSnail current sensor, using hall effect just like clamp meter, but instead of showing the current on a display the sensor output 0 to 5V, meaning you can connect it to a micro-controller to handle the data however your like. That’s nice, but while a clamp meter costs about $10, the 25A version of iSnail goes for $40, so I looked for alternatives. I wanted to find an always-on connected hall effect current sensor that either harvest energy or works of a fews with a battery, but did not find any, an instead discovered cheap current sensor modules based on Allegro Systems ACS712 supporting either 5A, 20A or 30A , working easily with analog inputs of Arduino boards, and selling for as low as $1 shipped on eBay for the 5A, while the 20A & 30A versions usually sell for less than $2.

ACS712The hardware specifications are pretty basic:

  • ACS712 Hall-Effect-Based Linear Current Sensor IC (Datasheet)
  • 2-pole terminal for DC or AC load
  • 3-pin header with VCC (5V), GND and OUT pins
  • Input Current and Sensitivity (measurement scale)
    • -/+ 5A – 185 mV/A
    • -/+ 20A – 100 mV/A
    • -/+ 30 A – 66 mv/A
  • Dimensions – 31 x 13mm

Since the IC can measure in both direction, OUT pin outputs VCC/2 (2.5v) when there’s no current, and other values which may be lower and greater than VCC/2 depending on current direction to report the actual current.

ASC712_ArduinoMeasuring DC current is very easily as you just need to take one measurement, subtract VCC/2, and divide this by the sensitivity. Alternative current is only a little more complicated as you have to take many measurement to find the RMS value as explained on Henry’s bench website. If you are playing with high voltage (110V/220V) be very careful, and using non-invasive current sensor might be a better idea, especially if you are a beginner.

Since the board had been available for a few years, there’s plenty of documentation on the web for Arduino. One person (Julian) did a pretty good video showing how it works.

ACS712 current sensor can also be interfaced with ESP8266, but since the wireless chip’s analog input only takes 0 to 1V, ACS712 output must be reduced leading to a lower accuracy, unless used via an external ADC chip. ESP32 won’t have this problem however as the analog input supports up to 0 to 4V range, although I understand ESP32 may has some built-in functions for energy monitoring.

Categories: Hardware, Video Tags: arduino, esp8266, power