|
Post by computourist on May 16, 2016 10:10:45 GMT
Hi, I finally had some spare time to do some coding... Have a look at: github.com/computourist/ESP8266-MQTT-client/blob/master/ESP_DIG_10/ESP_DIG_10.inoIt is a DIG node, but based on the ESP wifi module. It has the same capabilities as the RFM DIG client, and uses the same message format. This means you can easily incorporate it in an RFM-based Openhab system; mixing RFM and ESP nodes is OK. Some remarks: - the ESP DIG node connects directly to Mosquitto. NO gateway needed. This means a simpler setup for newbees. It also means remote nodes (as in: connected over the Internet) should be possible, but for this security needs to be enhanced. - The ESP nodes use a different topic in comparison to the RFM nodes. When using the same topic the RFM gateway will start complaining on not being able to reach nodes. - I tested this code on a simple ESP01 board with only 2 GPIO pins, but it should run on other modules as well. To flash the ESP module: - extend the Arduino IDE with the ESP code. See here for a tutorial.- put the ESP01 module on a breadboard with pull-up resistors (10k) on RST and CH_PD - connect it to your PC using an FTDI232 board (USB to serial) - pull GPIO00 to GND (direct or via 10 K pull down) to activate programming mode - connect 3.3 Volts to Vcc. - load sketch, change config to your needs and hit 'download' in the IDE to start compiling and flashing. Have fun, Computourist
|
|
gaute
New Member
Posts: 34
|
Post by gaute on May 16, 2016 19:56:12 GMT
|
|
gaute
New Member
Posts: 34
|
Post by gaute on May 16, 2016 20:02:52 GMT
BTW, have you tried to get the signal strength from the chip? I have a working example, but I am away on holyday now. I can implement it and make a pullrequest on the code when I get home, if you like...
|
|
ragoth
Junior Member
Posts: 64
|
Post by ragoth on May 19, 2016 15:09:52 GMT
Dear Computourist, I am really curious to try your compact wifi node. But I am getting compiling error. Please share the correct ESP8266.h library file as there are different versions in the net. Please share the Library file or its link. Thanks and best regards. Error Message: C:\Users\j\Documents\Arduino\libraries\ESP8266WiFi/ESP8266WiFi.h:23:26: fatal error: avr/pgmspace.h: No such file or directory
#include <avr/pgmspace.h>
^
compilation terminated.
Error compiling.
|
|
gaute
New Member
Posts: 34
|
Post by gaute on May 19, 2016 18:19:36 GMT
|
|
|
Post by computourist on May 19, 2016 19:15:34 GMT
|
|
|
Post by computourist on May 19, 2016 19:29:47 GMT
Looks nice. You could use the same schematic / build and have it function over mqtt with Openhab ;-) Wonder where they got this nice power plug .. It's not in the shopping list.
|
|
gaute
New Member
Posts: 34
|
Post by gaute on May 19, 2016 20:30:42 GMT
|
|
|
Post by computourist on May 20, 2016 7:02:08 GMT
|
|
ragoth
Junior Member
Posts: 64
|
Post by ragoth on May 20, 2016 16:00:44 GMT
Thank you computourist, I have upgraded the IDE and now it works. I am getting the following in the Serial Output: ...... WiFi connected IP address: 192.168.1.11 Connect to MQTT broker...connected topic home/esp_gw/nb/node80/dev99 value:NODE 80 WAKEUP topic home/esp_gw/nb/node80/dev03 value:WDIG V1.0 topic home/esp_gw/nb/node80/dev16 value:OFF topic home/esp_gw/nb/node80/dev03 value:WDIG V1.0 topic home/esp_gw/nb/node80/dev16 value:OFF topic home/esp_gw/nb/node80/dev03 value:WDIG V1.0 topic home/esp_gw/nb/node80/dev16 value:OFF
Now I will test complete functions and get back to you. Thanks again - ragoth.
|
|
|
Post by computourist on May 20, 2016 18:29:45 GMT
Congrats ragoth , have fun ! please do some extensive testing, as I haven't..
|
|
ragoth
Junior Member
Posts: 64
|
Post by ragoth on May 21, 2016 3:30:03 GMT
Hi Computourist, I tested the complete setup and it works fine with both the GPIO functions. Thanks and regards, Ragoth
|
|
gaute
New Member
Posts: 34
|
Post by gaute on May 21, 2016 19:42:33 GMT
Hi Computerist, Looking into your code, I have a question. Is there a reason why you make the mqttSubs function like this:
if (DID==16) { // state of actuator
if (readAction) {
sprintf(buff_topic, "home/esp_gw/nb/node%02d/dev16", nodeId);
if (ACT1State ==0) sprintf(buff_msg, "OFF");
if (ACT1State ==1) sprintf(buff_msg, "ON");
pubMQTT(buff_topic, buff_msg);
error = 0;
} else if (strPayload == "ON") {
ACT1State = 1;
digitalWrite(ACT1,ACT1State);
if (setAck) send16 = true;
error = 0;
} else if (strPayload == "OFF") {
ACT1State = 0;
digitalWrite(ACT1,ACT1State);
if (setAck) send16 = true;
error = 0;
} else error = 3;
} Instead of
if (DID==16) { // state of actuator
if (readAction) {
send16 = true; } else if (strPayload == "ON") {
ACT1State = 1;
digitalWrite(ACT1,ACT1State);
if (setAck) send16 = true;
error = 0;
} else if (strPayload == "OFF") {
ACT1State = 0;
digitalWrite(ACT1,ACT1State);
if (setAck) send16 = true;
error = 0;
} else error = 3;
} Since send16 contains the same code as the readAction for 16...
Might save som storage space on larger setups.
|
|
|
Post by computourist on May 22, 2016 13:17:20 GMT
You're right gaute , Last week it worked, but I didn't have time to review and clean up my code. Have a look at my github: a new and improved version 1.1 can be found there.
|
|
gaute
New Member
Posts: 34
|
Post by gaute on May 22, 2016 23:10:05 GMT
Hi, As promised, I have made a pullrequest to your git for RSSI support. I tested it, and it works. I have also made a pullrequest for a IP address on dev10. I think it would be a good idea, if you get a lots of units and you want to start debuging.
|
|
|
Post by computourist on May 23, 2016 19:30:49 GMT
Hi gaute , thanks for your effort. The IP address routine is incorporated in version 1.1. I will look at RSSI code, when I find some time...
|
|
|
Post by Thomas on May 28, 2016 15:41:24 GMT
Hi Computourist, nice to see a compact design using ESP8266. Thanks for your contribution. Please inform me, what are code blocks to be changed to use both GPIOs as input to monitor flame and gas sensor in the kitchen. Similarly how to change both GPIOs as output to control a fan and a light in the bedroom by a disabled or a senior citizen. Thanks in advance.
|
|
|
Post by computourist on Jun 5, 2016 8:27:34 GMT
Hi Computourist, nice to see a compact design using ESP8266. Thanks for your contribution. Please inform me, what are code blocks to be changed to use both GPIOs as input to monitor flame and gas sensor in the kitchen. Similarly how to change both GPIOs as output to control a fan and a light in the bedroom by a disabled or a senior citizen. Thanks in advance. Have a look at the code. It is self-explanitory. Also have a loook at the RFM69 threads, where others have modified and adapted node code. The RFM code is quite simular to the ESP code.
|
|
|
Post by computourist on Jun 5, 2016 8:29:03 GMT
gaute added functions to the ESP-node: - device 2 gives RSSI - device 10 gives the IP address of the node. Both changes are incorporated in version 1.2 of the ESP node code.
|
|
|
Post by Thomas on Jun 5, 2016 22:09:32 GMT
Thank you, As a newbie I am little confused to understand and follow your sketch because: 1. The button is not a straight on off function. One time functions as on and next time as off. 2. The button function is also not an independent outgoing function, it also toggles the local relay. 3.Similarity the relay is not controlled by incoming message only but locally by the button too. These interleaved codes makes me tough to separate the code blocks and understand its relevant functions, to modify on my own.
|
|
gaute
New Member
Posts: 34
|
Post by gaute on Jun 7, 2016 23:27:41 GMT
@thomas: 1. You need a momentary switch for the button. The ESP recognize it as on when you push it and off when you are not. 2. The button can be an outgoing function (Dev40). You can switch it on by altering "ackButton". 3. The relay can always be controlled by a incoming message. Dev16 accepts ON, OFF and READ. It can also be controlled by the button. There is a setting in the begin of the file, "toggleOnButton", which controls this. It can also be changed with Dev6. If enabled, every time you push the button the relay changes state (relay ON+Button press=OFF, relay OFF+Button press=ON).
Hope this helps..
|
|
|
Post by Thomas on Jun 8, 2016 0:28:40 GMT
Thank you, now I got it and will go through and try to understand the rest of the code. Regards.
|
|
|
Post by computourist on Jun 8, 2016 8:35:58 GMT
@thomas: 1. You need a momentary switch for the button. The ESP recognize it as on when you push it and off when you are not. 2. The button can be an outgoing function (Dev40). You can switch it on by altering "ackButton". 3. The relay can always be controlled by a incoming message. Dev16 accepts ON, OFF and READ. It can also be controlled by the button. There is a setting in the begin of the file, "toggleOnButton", which controls this. It can also be changed with Dev6. If enabled, every time you push the button the relay changes state (relay ON+Button press=OFF, relay OFF+Button press=ON). Hope this helps.. For completeness: if "toggleOnButton" is not enabled, pushing the switch starts a timer. The ON-time of the timer can be read or changed over device 7.
|
|
|
Post by computourist on Jun 8, 2016 13:59:14 GMT
|
|
gaute
New Member
Posts: 34
|
Post by gaute on Jun 9, 2016 22:13:20 GMT
Could be a cheap, safe and sturdy solution for those not so handy with a soldering iron.. Probably legal to (at least in Norway, where home made high voltage stuff is illegal).. BTW, made a new pullrequest with input voltage support. I struggled a bit with the sprintf settings, and ended with this: sprintf(buff_msg, "%d.%d", Vcc/1000, Vcc-((Vcc/1000)*1000)); Not very nice, but it works.. Change it if you have better solution... It is imporant to note, that this feature will NOT work if you use the ADC input port (available on ESP-07 and ESP-12). This should not be connected to anything if the VCC should work.. G
|
|
|
Post by computourist on Jun 10, 2016 9:47:20 GMT
....... BTW, made a new pullrequest with input voltage support. I struggled a bit with the sprintf settings, and ended with this: sprintf(buff_msg, "%d.%d", Vcc/1000, Vcc-((Vcc/1000)*1000)); You might try the decimal specifier: sprintf(buff_msg, "%0.2f", Vcc/1000);
|
|
|
Post by computourist on Jun 10, 2016 11:03:07 GMT
|
|
gaute
New Member
Posts: 34
|
Post by gaute on Jun 10, 2016 11:51:13 GMT
....... BTW, made a new pullrequest with input voltage support. I struggled a bit with the sprintf settings, and ended with this: sprintf(buff_msg, "%d.%d", Vcc/1000, Vcc-((Vcc/1000)*1000)); You might try the decimal specifier: sprintf(buff_msg, "%0.2f", Vcc/1000); I tried, it just outputs: topic home/esp_gw/nb/node80/dev04 value:%.2f
|
|
gaute
New Member
Posts: 34
|
Post by gaute on Jun 10, 2016 12:11:20 GMT
Early commits of the VCC pullrequest had some errors. The new one works fine!
|
|
|
Post by Thomas on Jun 10, 2016 12:49:05 GMT
@ computourist, Thank you so much for suggesting me all the options and links. Great!!
|
|