ESP8266 page
From Eric
m |
m |
||
Line 73: | Line 73: | ||
= Using MQTT = | = Using MQTT = | ||
- | * [http://www.penninkhof.com/2015/05/linking-the-esp8266-a-raspberry-pi-through-mqtt/ Connecting a Raspberry and an ESP using MQTT]. Mosquitto is used as the MQTT server. On the ESP, the client is [https://github.com/tuanpmt/esp_mqtt esp_mqtt]. On an Arduino, you may use [https://projects.eclipse.org/projects/technology.paho/downloads Paho] (which also supports Windows, Linux, and | + | * [http://www.penninkhof.com/2015/05/linking-the-esp8266-a-raspberry-pi-through-mqtt/ Connecting a Raspberry and an ESP using MQTT]. Mosquitto is used as the MQTT server. On the ESP, the client is [https://github.com/tuanpmt/esp_mqtt esp_mqtt]. On an Arduino, you may use [https://projects.eclipse.org/projects/technology.paho/downloads Paho] (which also supports Windows, Linux, and FreeRtos]. |
- | I have had some problem to setup Mosquitto on my old raspbian installation. | + | I have had some problem to setup Mosquitto on my old raspbian installation. |
+ | I had first to updgrade my installation: | ||
+ | sudo apt-get dist-upgrade | ||
+ | |||
+ | and then to follow the indications give non the Mosquitto website | ||
+ | curl -O http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key | ||
+ | sudo apt-key add mosquitto-repo.gpg.key | ||
+ | rm mosquitto-repo.gpg.key | ||
+ | cd /etc/apt/sources.list.d/ | ||
+ | sudo curl -O http://repo.mosquitto.org/debian/mosquitto-jessie.list | ||
+ | sudo apt-get update | ||
+ | sudo apt-get install mosquitto | ||
+ | |||
+ | |||
+ | == Setting up the MQTT server on windows == | ||
+ | |||
+ | |||
+ | == Compiling and installing the MQTQ client on the ESP8266== | ||
+ | To be completed. | ||
+ | |||
+ | == Compiling the MQTT client on the Raspberry Pi == | ||
+ | The simplest way uses [Paho] and Python: | ||
sudo pip install paho-mqtt | sudo pip install paho-mqtt | ||
Line 113: | Line 134: | ||
client.loop_forever() | client.loop_forever() | ||
+ | Let's try to compile paho on the Raspberry: | ||
+ | git clone https://git.eclipse.org/r/paho/org.eclipse.paho.mqtt.embedded-c | ||
+ | cd org.eclipse.paho.mqtt.embedded-c/ | ||
+ | make | ||
+ | |||
+ | Well, it should work but it doesn't: | ||
+ | mkdir -p build/output/samples | ||
+ | mkdir -p build/output/test | ||
+ | cc -o build/output/samples/pub0sub1 MQTTPacket/src/../samples/pub0sub1.c -lpaho-embed-mqtt3c -I MQTTPacket/src -L build/output | ||
+ | /tmp/ccV9SzgN.o: In function `main': | ||
+ | pub0sub1.c:(.text+0x148): undefined reference to `transport_open' | ||
+ | pub0sub1.c:(.text+0x1cc): undefined reference to `transport_sendPacketBuffer' | ||
+ | pub0sub1.c:(.text+0x29c): undefined reference to `transport_sendPacketBuffer' | ||
+ | pub0sub1.c:(.text+0x414): undefined reference to `transport_sendPacketBuffer' | ||
+ | pub0sub1.c:(.text+0x458): undefined reference to `transport_sendPacketBuffer' | ||
+ | pub0sub1.c:(.text+0x474): undefined reference to `transport_close' | ||
+ | pub0sub1.c:(.text+0x4a8): undefined reference to `transport_getdata' | ||
+ | collect2: ld returned 1 exit status | ||
+ | Makefile:106: recipe for target 'build/output/samples/pub0sub1' failed | ||
+ | make: *** [build/output/samples/pub0sub1] Error 1 | ||
+ | |||
+ | The makefile is erroneous and must be corrected as follows (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=472694 here]): | ||
+ | ${SYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/../samples/%.c ${srcdir}/../samples/transport.o | ||
+ | ${CC} -o $@ $^ -l${MQTT_EMBED_LIB_C} ${FLAGS_EXE} | ||
+ | |||
+ | |||
+ | And now it compiles smoothly. To run the samples, the LD_LIBRARY_PATH shall include "<wherever>/org.eclipse.paho.mqtt.embedded-c/build/output". | ||
=Other sources of information= | =Other sources of information= |
Revision as of 14:01, 27 April 2016
Contents |
The chip
The ESP8266 is a SoC designed by Espressif.
Someone managed to decap the chip (well, a similar one) and show its internal layout (source here):
The MCU is a Tensilica lx106 processor IP.
The board
I use the following board.
Connecting the ESP8266 board to a PC
The main things to know:
- VCC is 3.3V (NOT 5V).
- Input pins are NOT 5V tolerant.
- The power supply shall deliver at least 500mA.
- Pin CH_PD must be pulled-up to 3.3V
- Pin RST must be pulled-up to 3.3V.
The ESP8266 board pin-out is the following:
Using AT commands
Every command must end with a CR/LF sequence. On minicom, this can be obtained using CTRL-M followed by CTRL-J. The AT commands are fully described in Espressif manual "[|ESP8266 AT Instruction Set]".
Reprogramming the ESP8266
The ESP8266 can be reprogrammed. To do so, you can either go the easy way using Arduino or the hard way installing a cross-compiler, a firmware uploading tool, etc.
Using the Arduino environment
(To be completed.)
Building and installing the cross-compiler and sdk
I have followed the indications given here. A lot of information is also provided by Espressif on their BBS). In particular, a lot of documents are available on this page.
On a fresh MINT installation, here are the commands I had to type to get a complete development environment:
git clone --recursive https://github.com/pfalcon/esp-open-sdk.git cd esp-open-sdk/ sudo apt-get install autoconf sudo apt-get install gperf sudo apt-get install texinfo sudo apt-get install libtool sudo apt-get install automake sudo apt-get install ncurses-dev sudo apt-get install g++ sudo apt-get install expat make STANDALONE=y
A lot of very interesting/important information about programming the ESP8266 are given here.
Uploading the software to the chip
The chip can be placed in the flash programming mode by pulling up GPIO0 during reset (pull down GPIO0, pull down RESET, pull-up RESET).
A flash download tool is provided by Espressif here. Other tools:
Restoring the AT firmware
The AT firmware can be found [4] at Espressif.
Using MQTT
- Connecting a Raspberry and an ESP using MQTT. Mosquitto is used as the MQTT server. On the ESP, the client is esp_mqtt. On an Arduino, you may use Paho (which also supports Windows, Linux, and FreeRtos].
I have had some problem to setup Mosquitto on my old raspbian installation. I had first to updgrade my installation:
sudo apt-get dist-upgrade
and then to follow the indications give non the Mosquitto website
curl -O http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key sudo apt-key add mosquitto-repo.gpg.key rm mosquitto-repo.gpg.key cd /etc/apt/sources.list.d/ sudo curl -O http://repo.mosquitto.org/debian/mosquitto-jessie.list sudo apt-get update sudo apt-get install mosquitto
Setting up the MQTT server on windows
Compiling and installing the MQTQ client on the ESP8266
To be completed.
Compiling the MQTT client on the Raspberry Pi
The simplest way uses [Paho] and Python:
sudo pip install paho-mqtt
The python code (taken from I-don't-remember-where) connect to IBM test server :
host="messagesight.demos.ibm.com" port=1883 def on_connect(pahoClient, obj, rc): # Once connected, publish message print "Connected Code = %d"%(rc) client.publish("eric/test", "Hello World", 0) def on_log(pahoClient, obj, level, string): print string def on_publish(pahoClient, packet, mid): # Once published, disconnect print "Published" pahoClient.disconnect() def on_disconnect(pahoClient, obj, rc): print "Disconnected" # Create a client instance client=paho.Client() # Register callbacks client.on_connect = on_connect client.on_log = on_log client.on_publish = on_publish client.on_disconnnect = on_disconnect #connect x = client.connect(host, port, 60) client.loop_forever()
Let's try to compile paho on the Raspberry:
git clone https://git.eclipse.org/r/paho/org.eclipse.paho.mqtt.embedded-c cd org.eclipse.paho.mqtt.embedded-c/ make
Well, it should work but it doesn't:
mkdir -p build/output/samples mkdir -p build/output/test cc -o build/output/samples/pub0sub1 MQTTPacket/src/../samples/pub0sub1.c -lpaho-embed-mqtt3c -I MQTTPacket/src -L build/output /tmp/ccV9SzgN.o: In function `main': pub0sub1.c:(.text+0x148): undefined reference to `transport_open' pub0sub1.c:(.text+0x1cc): undefined reference to `transport_sendPacketBuffer' pub0sub1.c:(.text+0x29c): undefined reference to `transport_sendPacketBuffer' pub0sub1.c:(.text+0x414): undefined reference to `transport_sendPacketBuffer' pub0sub1.c:(.text+0x458): undefined reference to `transport_sendPacketBuffer' pub0sub1.c:(.text+0x474): undefined reference to `transport_close' pub0sub1.c:(.text+0x4a8): undefined reference to `transport_getdata' collect2: ld returned 1 exit status Makefile:106: recipe for target 'build/output/samples/pub0sub1' failed make: *** [build/output/samples/pub0sub1] Error 1
The makefile is erroneous and must be corrected as follows (see here):
${SYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/../samples/%.c ${srcdir}/../samples/transport.o ${CC} -o $@ $^ -l${MQTT_EMBED_LIB_C} ${FLAGS_EXE}
And now it compiles smoothly. To run the samples, the LD_LIBRARY_PATH shall include "<wherever>/org.eclipse.paho.mqtt.embedded-c/build/output".
Other sources of information
- ESP8266 community wiki
- Basic
- [5]: LUA on the ESP¨8266. You can build your version of NodeMCU on the net using site: configuration is done on the web site page and they buld the appropriate version of the firmware.
- http://www.labradoc.com/i/follower/p/notes-esp8266