An Inexpensive IoT Enabler Using ESP8266
-
Upload
mariusdanila8736 -
Category
Documents
-
view
216 -
download
0
description
Transcript of An Inexpensive IoT Enabler Using ESP8266
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Food Living Outside Play Technology Workshop
An inexpensive IoT enabler using ESP8266by gopinath.marappan on January 22, 2015
Table of Contents
An inexpensive IoT enabler using ESP8266 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Intro: An inexpensive IoT enabler using ESP8266 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 1: Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
What is ESP8266? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
MQTT is a machine-to-machine (M2M)/"Internet of Things" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2What is Thingspeak? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 2: Parts needed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Step 3: Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Step 4: Accounts on Cloudmqtt.com and Thingspeak.com . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Step 5: Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Before compiling: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Step 6: Flashing the firmware to the module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Step 7: Running the board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Step 8: View and control through Thingspeak.com . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Try it out yourselves !!!! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Step 9: View and Control using MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Step 10: Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Workaround . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Proper solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Step 11: Next steps and Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Intro: An inexpensive IoT enabler using ESP8266A major component of or rather the very concept, Internet of Things, is about how to connect various devices to the network so that they can both send data and receivecommands. Various technologies to address the last mile connectivity, such as bluetooth, wifi, NFC, etc... already exist, but most of these are complicated to deploy andoften need additional hardware such as a local control server or appliance.
In this instructable, I show you how to build and configure a simple standalone board that with the help of a wifi network can send environmental data to the internet andreceive control commands to turn on/off a switch. This project, which can be built for less than 10 or 15 US$ does the following:- Send temperature/humidity readings from a DHT11 sensor to a MQTT broker and a Thingspeak channel.
- Listen for MQTT messages and turn on or off a relay connected to ESP8266.
- Check a Thingspeak channel periodically and turn on/off a relay if the field has been updated.
In simple terms, this is a internet enabled temperature/humidity sensor and relay. The relay acts a two-way switch and can be used to turn on/off any AC applianceconnected to it. The parts needed cost only less than 15 US$ and absolutely no other hardware is needed. The software used is all open source and only free onlineservices have been used to connect the board to the internet. It is assumed there is a working wifi network available for the board to connect to.
Although a few instructables that show you how to configure a ESP8266 module to push data to the internet already exist, I have not seen a solution which also lets youcontrol a device attached to the ESP8266 module by receiving commands from the internet. This instructable shows ways to do that easily.
Step 1: BasicsWhat is ESP8266?
ESP8266 is a highly integrated chip designed for the needs of a new connected world. It offers a complete and self-contained Wi-Fi networking solution, allowing it toeither host the application or to offload all Wi-Fi networking functions from another application processor.
https://espressif.com/en/products/esp8266/.
http://mcuoneclipse.com/2014/10/15/cheap-and-simpl...
https://scargill.wordpress.com/?s=esp8266
What is Thingspeak?
MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messagingtransport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For example,it has been used in sensors communicating to a broker via satellite link, over occasional dial-up connections with healthcare providers, and in a range ofhome automation and small device scenarios.
http://mqtt.org/
http://en.wikipedia.org/wiki/MQTT
What is Thingspeak?
ThingSpeak is an open source Internet of Things application and API to store and retrieve data from things using HTTP over the Internet or via a Local Area Network.With ThingSpeak, you can create sensor logging applications, location tracking applications, and a social network of things with status updates.
https://thingspeak.com/
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Step 2: Parts needed1. ESP8266 ESP-01 module
2. DHT11 or DHT22 sensor
3. 5v relay
4. LM1117 3.3v LDO voltage regulator
5. 1 x 470 uF capacitor
6. 2 x 10 uF Tantalum capacitor
7. 2 x 1K resistor
8. 1 LED
9. male breakaway headers
10. PCB Board
11. FTDI USB to TTL adapter cable
The ESP8266 module, the DHT11/22 sensor and the USB to TTL cable can be ordered from ebay.com and all three of them together should not cost more than $9.00.And the rest of the components can be bought from any electronic shop for a couple of dollars.
A working wifi access point and its login details should be available for the ESP8266 module to connect to.
Image Notes1. ESP8266 ESP-01 module2. 5v relay3. DHT11 temperature/humidity sensor
Image Notes1. FTDI USB to TTL adapter cable - only needed for flasing the firmware2. 5v DC 1A adapter
Step 3: CircuitThe circuit is pretty simple.
The board can be powered either by just the USB cable or through a 5v DC supply connected to the power socket at the top. A LM1117-3.3 LDO is used to get 3.3vneeded for the ESP8266 module. A DHT11 sensor is connected to GPIO2 pin of ESP8266.
The GPIO0 pin can be connected to the ground or relay based on the jumper position.
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Step 4: Accounts on Cloudmqtt.com and Thingspeak.comThe board pushes temperature and humidity readings as well as the relay state to:
MQTT broker: Any MQTT (http://mqtt.org/) broker can be used. In my case, I have used a free online broker at www.cloudmqtt.com. You would need to create anaccount as well as an instance. And enter the instance details in user_config.h. An advantage of using an online broker is that it can be accessed from anynetwork. If a local broker is used (for example, running on a local Raspberry Pi box), then it may be difficult to access it from outside the home network sinceincoming ports are usually blocked by ISPs.
Thingspeak.com: An account needs to be created on Thingspeak.com. Additionally, a channel with these three channels also needs to be created and its detailsentered in user_main.c:
field1 - relay statefield2 - temperaturefield3 - humidity
Although in its present form, the board needs both cloudmqtt and Thingspeak connectivity for all functions to work properly, the code can be easily tweaked to use onlyone of these options.
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Step 5: CodeThe code is available at:
https://github.com/tangophi/esp_mqtt
Before compiling:
Configure ESP8266 build environment using steps in http://signusx.com/esp8266-windows-compilation-tut...Update user_config.h and change MQTT host and login details as well as WiFi login details.
#define MQTT_HOST "your cloudmqtt instance name"#define MQTT_PORT your cloudmqtt instance port
#define MQTT_USER "your cloudmqtt instance username"#define MQTT_PASS "your cloudmqtt instance password"
#define STA_SSID "your WiFi SSID"#define STA_PASS "your WiFi password"
Update following two global variables in user_main.c to your values:
char YOUR_THINGSPEAK_API_KEY[]= "xxxxxxxxxxxxxxxxx";
char YOUR_THINGSPEAK_CHANNEL[]= "xxxxxxxxx";
Build target 'all'.
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Step 6: Flashing the firmware to the module* Connect GPIO0 to ground by putting the jumper in the proper position as shown in the figure.* Disconnect and reconnect the USB cable to reset the ESP8266 module.
* Flash the firmware.
Image Notes1. jumper connects GPIO0 to ground. For flashing the firmware.
Step 7: Running the boardRemove the jumper.Power the board using either the USB cable or a 5v DC power supply. Make sure the power to the ESP8266 module is reset after the jumper is removed.After a couple of seconds, put the jumper in a position to connect GPIO0 to the relay.Open CoolTerm or RealTerm window and connect to the correct COM port. An output like the following indicates everything is running fine.
WIFI_INIT
MQTT_InitConnection
MQTT_InitClient
System started ...
mode : sta(18:fe:34:9d:f5:36)add if0
DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %scandone
DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %STATION_IDLE
add 0
aid 4
pm open phy_2,type:2 0 0
cnt
connected with dlink, channel 2
dhcp client start...
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
STATION_IDLE
STATION_IDLE
DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
ip:192.168.0.104,mask:255.255.255.0,gw:192.168.0.1
DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %TCP: Connect to domain m11.cloudmqtt.com:19449
DNS: found ip 107.22.157.224
TCP: connecting...
MQTT: Connected to broker m11.cloudmqtt.com:19449
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: data received 4 bytes
MQTT: Connected to m11.cloudmqtt.com:19449
MQTT: Connected
MQTT: queue subscribe, topic"/esp8266/temperature", id: 1
MQTT: queue subscribe, topic"/esp8266/humidity", id: 2
MQTT: queue subscribe, topic"/esp8266/relay", id: 3
MQTT: Sending, type: 8, id: 0001
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0002
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
MQTT: Sending, type: 8, id: 0003
TCP: Sent
TCP: data received 5 bytes
MQTT: Subscribe successful
DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %DHT: 24 00 1b 00 [3f] CS: 3fTemperature = 2700 *C, Humidity = 3600 %DHT: 23 00 1b 00 [3e] CS: 3eTemperature = 2700 *C, Humidity = 3500 %DHT: 23 00 1b 00 [3e] CS: 3eTemperature = 2700 *C, Humidity = 3500 %DHT: 23 00 1b 00 [3e] CS: 3eTemperature = 2700 *C, Humidity = 3500 %
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Temperature: 27.0 *C, Humidity: 35.0 %
MQTT: queuing publish, length: 28...
MQTT: queuing publish, length: 25...
MQTT: Sending, type: 3, id: 0000
TCP: Sent
MQTT: Published
TCP: data received 28 bytes
MQTT topic: /esp8266/temperature, data: 27.0
MQTT: Sending, type: 3, id: 0000
TCP: Sent
MQTT: Published
TCP: data received 25 bytes
MQTT topic: /esp8266/humidity, data: 35.0
DHT: 23 00 1b 00 [3e] CS: 3eTemperature = 2700 *C, Humidity = 3500 %In http_post_callback... http_status=200
response===82===
DHT: 23 00 1b 00 [3e] CS: 3eTemperature = 2700 *C, Humidity = 3500 %In http_get_relay_state_callback... http_status=200
response===3
1.0
0
===
Sending on to /esp8266/relay...
MQTT: queuing publish, length: 20...
MQTT: Sending, type: 3, id: 0000
TCP: Sent
MQTT: Published
TCP: data received 20 bytes
MQTT topic: /esp8266/relay, data: on
DHT: 23 00 1b 00 [3e] CS: 3eTemperature = 2700 *C, Humidity = 3500 %In http_post_callback... http_status=200
response===0===
DHT: 23 00 1b 00 [3e] CS: 3eTemperature = 2700 *C, Humidity = 3500 %DHT: 23 00 1b 00 [3e] CS: 3eTemperature = 2700 *C, Humidity = 3500 %
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Image Notes1. 1st step - make sure jumper is removed and board is not powered up.
Image Notes1. 2nd step - Connect power supply to the board with the jumper still removed.
Image Notes1. 3rd step - Put back the jumper so it connects GPIO0 to relay. Board should runnormally now.
Image Notes1. LED is lit - indicates the relay is active (turned on)
Step 8: View and control through Thingspeak.comView
The temperature/humidity readings as well as the relay state can be seen at
https://thingspeak.com/channels/21370
Control
For switching on the relay, the field1 of the Thingspeak channel should be updated to 1.0 using the following URL:
https://api.thingspeak.com/update?key=YF2DC4HXFSUQ...
Simply copy/paste the above URL in a browser window. If the response returned is a non-zero integer, it means that the field has been updated correctly. If a zero isreturned, then try copy/paste the URL again till you get a non zero integer.
For switching off the relay, the field1 of the Thingspeak channel should be updated to -1.0 using the following URL:
https://api.thingspeak.com/update?key=YF2DC4HXFSUQ...
Try it out yourselves !!!!
The board is online and you are welcome to turn on/off the switch by sending commands using the above URLs. I have connected a low power AC bulb to the relay and itwill turn on or off :)
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Step 9: View and Control using MQTTView
Any MQTT client can be used to connect to the cloudmqtt broker to display the messages published by the board. I have used a Chrome App called MQTTlens.
Control
A message can be 'published' to the /esp8266/relay topic using a MQTT client to turn on/off the relay.
Step 10: IssuesThere is a small issue in the circuit. If the board is powered on with the jumper connecting GPIO0 to the relay, then the relay switches on immdiately, but the board doesnot boot up properly. I suspect that the relay may be momentarily drawing too much current.
Workaround
A workaround for this issue is to power on the board with the jumper removed. After a couple of seconds, the jumper can be inserted to connect GPIO0 to the relay andeverything works fine after that.
Proper solution
I guess a inverter can be between GPIO0 and the relay. So initially GPIO0 is HIGH and hence the relay should not turn on automatically on power up and the ESP8266module should boot up fine. Later on to turn on the relay, GPIO0 can be made LOW and to turn off the relay it can be made HIGH.
Step 11: Next steps and ConclusionIn this project, we have seen how a standalone ESP8266 module can be used to talk to the Internet to publish data as well as to receive commands. A ESP-01 modulewas used which has two GPIO ports only.
Instead of a ESP-01 module, if a ESP-03 module is used, then more sensors can be attached. However, there are still only 6 GPIO ports on ESP-03 modules. ESP-12has 8 GPIO ports.
Anyway, a ESP-01 module can be used in conjunction with an Arduino board to connect more sensors and even a display. The ESP-01 module should still have thestandalone firmware such as the one used in this project (and not the AT firmware) and can talk to the Arduino through the UART port.Plans for next project include having a ESP8266 module connected to an Arduino with LCD display, motion detector, more relays and other sensors. Also develop anAndroid app to control the board through thingspeak or mqtt.
All suggestions/comments are welcome. Please feel to use the code/design in this instructable as you may please. If you make something interesting out of thisinstructable, a message on what it is would be nice :)
Related Instructables
ESP8266 WiFitemperature andhumidity sensorby EasyIoT
ESP8266 WiFirelay switch byEasyIoT
Use ESP8266 toInternet enabledAC Appliancesby shinteo
Easy ESP8266WiFi Debuggingwith Python byjimk3038
A newbie'sguide to setupESP8266 withArduino Mega2560 or Uno byshinteo
ESP8266 WifiTemperatureLogger bynoelportugal
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
Advertisements
Comments20 comments Add Comment
gast says: Feb 10, 2015. 12:14 PM REPLYNice project. How did you get thingspeak to send something back to the esp8266?Thanks
gopinath.marappan says: Feb 10, 2015. 6:29 PM REPLYThanks!
Well, thingspeak doesn't send any data on its own to the module. Rather, the modules gets the last value of the relay field from thingspeak once everyminute and if there is a change in the value, then it will activate/deactivate the relay.
I agree this is not an ideal way to do it, but for this instructable, I wanted to find free and easy to configure services to demonstrate what can be done withESP8266.
If you are planning to make something like this and want a way to control the module from the internet, check out devicehub.net. Came across this yesterdayonly. I believe with devicehub, you can send data to the cloud through MQTT and have it displayed graphically. Also, since it uses MQTT, two waycommunication is also possible. You can think of devicehub as a combination of cloudmqtt and thingspeak in terms of functionality.
Apart from this, there are several other ways to manage/monitor/control an ESP8266 module from the internet. But I feel that sending and receiving datafrom several ESP8266 modules directly to and from the cloud is a bit of a stretch. Think about the bandwidth being used. Instead a local server (raspberry pior something like that) should talk to the ESP8266 modules and then have another interface setup so that the interface can be accessed from anywhere.I am thinking about a project that will have a PIR motion sensor attached to ESP8266 module and will send a SMS alert to my phone if there is movementdetected when it is "armed" like a burglar/security alarm.
gast says: Feb 11, 2015. 10:43 AM REPLYVery clever use of Thingspeak. I think I will give that a go. I am surprised that Thingspeak does not have the ability to add buttons and such forcontrol purposes. I had a look at devicehub and it looks promising. Thank you for taking the time to answer my question and for sharing your project.
madaerodog says: Feb 16, 2015. 12:52 PM REPLYHey guys, devicehub developer around here, that looks like the most cheap capable board ever for IOT, we ordered a few to test out, meanwhileif you want to give us a go and have any questions or need of help ping us at http://ask.devicehub.net
Thanks,
Constantin
gopinath.marappan says: Feb 17, 2015. 7:24 AM REPLYHi Constantin,
Yes indeed. As far as I can see, this is the cheapest standalone (apart from a wifi connection) board to connect to the internet. Hope you havebeen reading about the ESP8266 modules - there are several variants - mainly depending on how may GPIO ports are available.
I have started working on a new project and i plan to use devicehub.net in it. I have already seen the board successfully sending data todevicehub.net through MQTT. And I believe receiving commands from devicehub.net should be okay too.
Btw, do you know how to secure the MQTT connection from a user computer (or ESP8266 module) to devicehub.net. Is this something that youplanning to add in the future?
Thanks,
Gopi
icotoi1 says: Feb 18, 2015. 6:28 AM REPLYIn the current online version of devicehub.net, the MQTT connection security is provided by the project API key, i.e. if you don't give theAPI key to a 3rd party, you should be OK.
In the upcoming release of devicehub, security is much tighter and there are various means of device authentication and authorizationusing SSLv3 that we have in the works.
gopinath.marappan says: Feb 11, 2015. 12:55 PM REPLYYou are very welcome. Please do let me know when your project is complete.
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
icotoi1 says: Feb 16, 2015. 1:18 PM REPLYUsing devicehub.net MQTT APIs, the internet bandwidth consumption should be marginal, also the latency should be very low (less than 40ms),depending on your location and internet connection.
gopinath.marappan says: Feb 17, 2015. 7:17 AM REPLYTrue. I had been using MQTT for a different project earlier (where two Arduinos talk to a MQTT broker on a RPi along with several python scripts onthe RPi) and I was totally hooked on this protocol, its functionality and mainly its ease of use.And when Tuan PM ported MQTT to ESP8266, I knew this is the right protocol for ESP8266. when I made this instructable, i wasn't aware ofdevicehub.net. Hence, I used cloudmqtt and thingspeak and a roundabout way to send commands from thingspeak to the ESP8266 module.
Anyways, I am working on a new project now and have already seen it talking to devicehub.net properly. But I think it will take me two or three weeksmore to make a instructable of the new project - i have several ideas for that project. Lets see how it goes.Btw, do you also work for devicehub.net like madaerodog (see his comment below)?
gopinath.marappan says: Feb 17, 2015. 7:17 AM REPLYTrue. I had been using MQTT for a different project earlier (where two Arduinos talk to a MQTT broker on a RPi along with several python scripts onthe RPi) and I was totally hooked on this protocol, its functionality and mainly its ease of use.And when Tuan PM ported MQTT to ESP8266, I knew this is the right protocol for ESP8266. when I made this instructable, i wasn't aware ofdevicehub.net. Hence, I used cloudmqtt and thingspeak and a roundabout way to send commands from thingspeak to the ESP8266 module.
Anyways, I am working on a new project now and have already seen it talking to devicehub.net properly. But I think it will take me two or three weeksmore to make a instructable of the new project - i have several ideas for that project. Lets see how it goes.Btw, do you also work for devicehub.net like madaerodog (see his comment below)?
paulle says: Feb 16, 2015. 12:56 PM REPLYI m new to this SDK and found your project interesting. Couple questionsWhat does the user_init function do? And user_main.c file?
Is your code an added on to the firmware or does it overwrite the firmware?
gopinath.marappan says: Feb 17, 2015. 7:07 AM REPLYFor this project, I just modified Tuan PM's code (https://github.com/tuanpmt/esp_mqtt) and made my firmware and hence didn't have to start from scratch.But from what I understand, user_main.c is kinda like the main source file - for example it is equivalent to the file that contains main() in standard C. Anduser_init() function is like a setup/configure function.If you are familiar with Arduino programming, you can think of user_init() as the setup() function in Arduino. Similar to Arduino's loop() function, we can havea loop() in this SDK also, but it may not have to be named as loop() as such. Please refer to this link for more info about the basics of this SDK:http://41j.com/blog/2015/01/esp8266-run-loop-messa...In my project however, there is no loop() function. Instead I use a timer to trigger timer_callback() function periodically. In essence this acts like a kind of aloop.
Also, when you build a firmware from my code or a modified version of my code, that firmware will completely overwrite the firmware on the ESP8266module. In other words, the firmware is self-contained and does not rely on any other firmware.
I totally understand that the ESP8266 SDK is kind of hard to start with, since the documentation accompanying it is not very easy to understand. If you areseriously interested in ESP8266, I suggest you start with some sample programs in the SDK and then go onto Tuan PM's code and finally my code. My codehas combined Tuan PM's MQTT code with Caerbannog's httpclient code(https://github.com/Caerbannog/esphttpclient), so may not be the best place to startas such, if you are new to this SDK.
Hope this helps.
vsomu says: Jan 26, 2015. 10:13 AM REPLYI made it based on your inputs. I am able to view data on thingspeak.com. but could not receive data from cloudmtt.com
need to look into this problem.
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
gopinath.marappan says: Jan 27, 2015. 10:37 AM REPLYNice. Good to know that my instructable has been helpful and also that your board works.
About mqtt, make sure the cloudmqtt account details are entered properly. You should also see if using any mqtt client on your computer (MQTTlensChrome App) and/or a phone (MyMQTT Android), if messages are getting sent properly from one to another though cloudmqtt. If that works, then it shouldalso work from esp8266. I did not have any issues with mqtt. It just worked :)
vsomu says: Feb 2, 2015. 9:13 AM REPLYThanks gopinath for clear reply.
yes it was issue in cloudmqtt credentials, i corrected it. now it is connecting to cloudmqtt and publishing the data.
another question i have is the device is keep resetting with load.., during this reset, relay is making a switch on and off. why device is restarting? anyclue? did you get similar behaviour?
below is the sample log collected. please let me know any observations found.
wdt reset
load 0x40100000, len 32324, room 16
tail 4
chksum 0xaf
load 0x3ffe8000, len 2732, room 4
tail 8
chksum 0xb2
load 0x3ffe8ab0, len 8632, room 0
tail 8
chksum 0xc6
csum 0xc6
r,DHT setup for type 0
load ...WIFI_INIT
MQTT_InitConnection
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/
MQTT_InitClient
System started ...
mode : sta(18:fe:34:9e:65:15)add if0
DHT: 25 00 1a 00 [3f] CS: 3fTemperature = 2600 *C, Humidity = 3700 %DHT: 25 00 1a 00 [3f] CS: 3fTemperature = 2600 *C, Humidity = 3700 %STATION_IDLE
STATION_IDLE
STATION_IDLE
gopinath.marappan says: Feb 3, 2015. 7:59 AM REPLYThat's great news Somu! Is MQTT really cool or what :) With MQTT, all that is needed is for a proper front end user interface. I have designed a webpage to display MQTT messages and also send commands through MQTT when buttons are pressed, but its for a different project. You need a webserver to host the page though.
But if someone can write an ios/android app that subscribes to a MQTT server and graphically display data as well as buttons to send commandsback to esp8266, it will be just awesome. Imaging, all you need for that will be a ESP8266 board, wifi connection, a MQTT broker (free public onesavailable) and an app. I dont know, but I think with this, we can avoid most of the complexity with existing home automation solutions. Frankly, i havenot tried any end-to-end home automation solution, so I really shouldn't comment. But when I checked whats available, almost everything needssome kind of a software running on a home server or the cloud and different kinds of protocols and such.
Anyway, I have not seen such automatic restarts with my board. Is your board/module restarting only when the relay is activated or even when it isdeactivated? Is it just restarting or is it crashing and booting up again?Remember I mentioned an issue with my board in the instructable where the module was not starting properly if it is powered up with the relayconnected to GPIO0. I actually built a second board with a HC04 inverter between GPIO0 and the relay and now that board powers up fine witheverything connected. And the board has been running fine for almost a week now. I don't know if it automatically restarts in between, i suspect itmight, but even if it does, it automatically connects back.
In your case, is the module not connecting back to the wifi automatically and sending data again when it restarts?
Also, you might want to check out the original ESP8266 MQTT code maintained by Tuan. He is doing a great job updating it almost continuously andI believe the current code is pretty stable and in terms of memory usage too from what I gather. Also, we have a new esp8266 SDK too. My code is abit old and I have not updated my repo with the latest from Tuan's.
chrisrust says: Jan 31, 2015. 8:45 PM REPLYHi, thanks for the great instructable. I was wondering if there was any chance you could elaborate on the process of updating the user_config.h settings andthe global variables in user_main.c. Where are those files located?
I'm in the process of trying to follow the blog you linked to about configuring the ESP8266 build environment but I have not been successful yet. Is it possibleto use a pre-compiled build from somewhere?
Again thanks for the posting your project. I'm doing my best to try and recreate it.
gopinath.marappan says: Feb 1, 2015. 12:52 PM REPLYDid you download my git repo from the given link? The files should be in ~/config and ~/user folders. Are you not seeing them?
Configuring the build environment is not easy i guess. I tried several times and followed instructions from several links before i could get it right. Eventually, Ithink all that is needed is to install Python 2.7, MinGW, Espressif ESP8266 Devkit and Eclipse. But you need to kind of experiment to get it right. I am notsure about the exact steps that I followed though since I tried several times.
And since settings are defined in the firmware, I am afraid a pre-compiled build will not be of much help.
Let me know what exact issues you are facing with configuring the build environment. if its something that I have seen, may be I can be of help.
Thanks for reading my instructable and trying to re-create it :)
chrisrust says: Feb 1, 2015. 7:10 PM REPLYThank your for the suggestions. It will be several days before I have time to get back to the project but I will let you know how it goes.
vsomu says: Jan 25, 2015. 9:31 AM REPLYGr8 work Gopinath,
Very nice explanation. was eagerly looking for this kind of project using MQTT with ESP8266 since quite a bit of time. happy to see this intractable.i am going to build the same.
Your future idea is very nice, it might be good to use ESP-12 and control LCD through i2c directly from ESP8266 board by using i2c bit banging mechanism.so that there will not be any arduino requirement. this is just an thought of me.
-
http://www.instructables.com/id/An-inexpensive-IoT-enabler-using-ESP8266/