-->
Page 1 of 4

DeviceHive firmware for ESP8266

PostPosted: Wed Aug 12, 2015 12:13 pm
by Nikolay-DH
Hello everyone!
I'm happy to present DeviceHive firmware for ESP8266!
DeviceHive is an Open Sources platform for IoT solutions.

Overview
DeviceHive firmware for ESP8266 is suppose to connect simple electronic devices with common interfaces to DeviceHive cloud service. Having this firmware on ESP8266 there is no need to write programs for hardware. Chip connects to specified remote DeviceHive server(which can be deployed in local network or in some cloud service) and waits for commands. Each command suppose to use some electronic interface to control some hardware connected to chip. It can be simple interaction with GPIO pins for turning on/off simple LED, relay or waiting some changes on pin from sensor. Also it is possible to connected more complicated sensors and actuators using UART or I2C bus. In other words, this firmware move the most commonly used interfaces right into cloud service where you can control your devices or even network of devices from any distance, from any point.

Example of connecting SSD1306 base OLED display: https://www.youtube.com/watch?v=gKgU6RzaxFU
Source code of program that sends data to display: https://github.com/devicehive/esp8266-f ... ample.html

DeviceHive server have two endpoints to send command commands or receive notifications: HTTP and Websocket. Developers can use any programming languages, any developer tools, any SDK that they prefer to interact with server and as a result with hardware. It is possible because all commands represent simple JSON string which sends via HTTP or Websocket. For example sending command with JavaScript looks like:
Code: Select all      var xmlhttp = new XMLHttpRequest(); 
      xmlhttp.open('POST','http://exmaple.com/api/device/deviceId/command', true);
      xmlhttp.setRequestHeader('Authorization', 'Basic ' + btoa('user:password'));
      xmlhttp.setRequestHeader('Content-type', 'application/json;charset=UTF-8');
      var myjson = {};
      myjson['command"] = 'uart/write';
      myjson['parameters'] = {'data':'SGVsbG8sIHdvcmxkIQ=='};
      xmlhttp.send(JSON.stringify(myjson));

After receiving this command chip prints 'Hello, world!' in UART bus. The same idea with other interfaces.

Getting started:
First at all firmware have to be flashed into chip memory and chip have to be configured for using specified Wi-Fi network and DeviceHive server. Developers can build firmware and all tools for flashing and configuring by himself from sources. Or it can be downloaded from git repository: go to https://github.com/devicehive/esp8266-f ... er/release and download archive with the latest version.
For flashing chip needs to be connected to computer via USB-UART converter, CH_PD pin have to be connected to Vcc, GPIO15 and GPIO0 have to be connected to ground and 3.3 power supply should be used.
After assembling, connect it to computer. Install driver for your USB->UART converter. Make sure that virtual serial port is available in your system( virtual COM is present on Windows OS, '/dev/ttyUSB*' on Linux, '/dev/tty.*' on OS X). Unpack archive with firmware and flash it running 'esp-flasher-<your-os>' in terminal. Flasher automatically detects serial port and use '0x00000.bin' and '0x40000.bin' files for flashing. You can also you esp-tool for flashing - https://github.com/themadinventor/esptool
Now remove wire from GPIO0(live it float or connect to high), reboot device and connect to firmware with with 'esp-terminal-<your-os>' util. You can also use any other util that can connect to terminal via UART and support escape sequences, PuTTY or GNU 'screen' for example. Port parameters are: 115200 8N1.
Firmware terminal is a unix like terminal with few commands. It exists for chip configuring and debugging. To see debug output type 'dmesg'. To configure run 'configure' command. Follow instructions in terminal. You need to know DeviceHive server credentials for configuring. If you don't have DeviceHive server instance you could use free playgroun on DeviceHive site. Follow to http://devicehive.com/playground and register there and you will have your own DeviceHive server instance. DeviceHive server can be deployed in local network or on some cloud hosting services. Follow for DeviceHive server deployment instructions on http://devicehive.com
After rebooting you can send commands to DeviceHive server and ESP8266 perform them. List of accepted command is in this document - https://github.com/devicehive/esp8266-f ... SP8266.pdf You can use DeviceHive web admin control panel to send command for test purpose or learning. Go in web admin, 'Devices' tab, 'commands' subtab, 'enter new command'. Type command and parameters and press 'push'. After ESP8266 perform your command you can press 'refresh' button to see result.

You can find more detail instructions with images in 'DeviceHiveESP8266.pdf' file in archive with firmware. Or https://github.com/devicehive/esp8266-f ... SP8266.pdf (but be careful with only version, it can be newer than your firmware version)

Download
https://github.com/devicehive/esp8266-firmware/releases

Hope this firmware will be useful for your IoT or DIY projects! Any questions are welcome. Thank you!

Re: DeviceHive firmware for ESP8266

PostPosted: Thu Aug 13, 2015 5:47 am
by iwalker
Very interesting - thanks for sharing.

Your PDF is nicely written and I was able to flash and configure module without any issues.
I am using your server but I am unable to establish contact with it.

terminal debug message - connector error occurred - connection aborted.
I can ping the specified device hive IP.

For hobbyists like me coming from an electronics background vs computer development some very basic tutorials on how to write a program to interact with the device would be nice - which toolchains and dev ide are needed etc and some first steps.

Tx
Ian

Re: DeviceHive firmware for ESP8266

PostPosted: Thu Aug 13, 2015 2:28 pm
by Nikolay-DH
Hello Ian,

This error means that esp8266 can't establish TCP connection with server. Server refuse connection, esp8266 tries to establish connection with wrong host or some firewall blocks access on the route.
First at all, check if you can open API Url in browser on computer or phone which is connected to the same Wi-Fi network. Just type it in browser address line. Browser should open page with content like:
The DeviceHive RESTful API is now running, please refer to documentation to get the list of available resources.

Api Version: 2.0.0
Server Timestamp: 2015-08-13T19:01:52.142000

for example you can try this url: http://nn8354.pg.devicehive.com/api - it will show page above. If something wrong check your internet connection, firewalls, dns servers.

Then check if you correctly typed API Url in ESP terminal. Run 'config' command it should print output like:
Code: Select all$ config
Wi-Fi SSID: LNET
DeviceHive Server: http://nn8354.pg.devicehive.com/api
DeviceHive DeviceId: esp-device

i.e. 'DeviceHive Server' should contains correct scheme and all slashes and dots in right places. And url has to contain domain address(not IP) for playgrounds. Try to ping domain(not IP, without url scheme and path) in ESP8266 terminal. Is it resolving correct IP address? Compare it with https://toolbox.googleapps.com/apps/dig/ For example:
Code: Select all$ ping nn8354.pg.devicehive.com
Resolving...
Host nn8354.pg.devicehive.com IP is 50.57.84.170
32 bytes received from 50.57.84.170 in 317 ms, icmp_seq = 1
32 bytes received from 50.57.84.170 in 248 ms, icmp_seq = 2
32 bytes received from 50.57.84.170 in 236 ms, icmp_seq = 3
32 bytes received from 50.57.84.170 in 195 ms, icmp_seq = 4
Total sent: 4, received: 4, lost: 0, average time: 249 ms


Succesfull firmware start in debug output looks like:
Code: Select all$ dmesg
Debug output enabled. Press 'q' for exit.
*****************************
Settings successfully loaded from main storage
Initialization complete
WiFi event STAMODE_CONNECTED
WiFi connected, ip: 192.168.0.104
Resolving nn8354.pg.devicehive.com
Host nn8354.pg.devicehive.com ip: 50.57.84.170, using port 80
Info request created, 213/213
Send info request...
Timestamp received 2015-08-13T19:18:07.707000
Poll request created, 276/276
Register request created, 394/394
Send register request...
Successfully register
Send poll request...


Thank you for using DeviceHive!
Nikolay

Re: DeviceHive firmware for ESP8266

PostPosted: Sat Aug 15, 2015 10:55 pm
by iwalker
Hi Nikolay

Thank You very much for such a detailed response. I reconfigured the device from Your terminal application and all is ok now so must have been a finger fault from my side on initial configuration. Thanks again for making this available and all the best with the project.