ESP-adapter

Dear all,
Has someone succeeded in using the ESP-adapter for connection of an arduino or an ESP8266 to the Things gateway?

I am familiar with the use of ESP8266 and I have been using the cheap ESP-01 in several projects based on arduino programming.

I have uploaded the espThing.ino file to an ESP-01 module and have changed the password and username for wifi access. Looking in the serial communication it connects to my wifi and is in listening mode as it should be.

I installed the ESP-adapter via the gateway frontend software, and I have changed the IP address start and end in the package.json file on the Raspberry Pi gateway, so it fits to my home network as described in the Readme file on Github:

The ESPadapter is listed in the Adapters menu under Settings, but an ESP device is not showing up at the Things gateway, when searching for new devices. What did I miss to make it work ?

Anyway thank you so much for your efforts with this open source platform for an unified way of accessing all kind of IoT devices. I hope you will succeed with this project. So far I have Phillips Hue bulbs available on my gateway but is hoping to use the cheap ESP-01 modules for all kind of devices. This could be a big success in the Maker communities.

Br, Olav

Hi,

i experienced the same problem, unfortunately i don’t have a solution yet. Looking at gateway/run_app.log, it says it’s started the pairing, iterating IPs in the range i defined. It actually finds my devices, saying “Adding device …”, but later runs in a pairing timeout, which results in the new thing not being added.

i attachedmy log file, (screenshot only from my rpi :wink: Not sure wether this bug (?) is within the ESP-adapter or the gateway. or its a misconfiguration from my side…

IMG_0741

Best,
Andreas

I have been doing some more de-bugging now and have realized a strange thing.
When changing the IP range in package.json, I need to restart the service by:

sudo systemctl restart mozilla-iot-gateway.service

before it takes effect. Doing that makes the ESPadapter go away, and I need to activate it again using add-ons. This overwrites the package.json file in the ESP-adapter folder, and I am back to the standard IP range that comes with the ESP-adapter library and the ESP-01 device cannot be found when scanned.

What can I do ?

image

I am having the same issue.

Also, I see this repository:

It mentions “This can be added to the Gateway using the “Add Thing by URL” feature.”

Is this available yet? What are are the implications of “adding by URL”?

@olavgullaksen upon restart and initialization of the adapter, the gateway takes its config from package.json and writes it to the database. You can take an sqlite3 client and delete the row from the settings table, then it’s back to defaults (upon next restart of the gateway).

The configuration is copied from the package.json file into the database when the adapter is first installed. Changes need to be made in the database and not in the package.json file (which is essentially just providing the very first initial configuration).

We do provide a little helper script which can be found in the /home/pi/mozilla-iot/gateway/tools directory and is called config-editor.py. This wiki page: https://github.com/mozilla-iot/wiki/wiki/Configuring-GPIO-for-use-with-the-gpio-adapter has some information about configuring the gpio-adapter using the config-editor.py script. You would do the same thing for the esp adapter, except use the name ESP-adapter (I suspect that it’s case sensitive).

That should work until the add-by-URL feature is supported (which might be now - I just back from several weeks of vacation, so YMMV)

2 Likes

@dhylands, thanks a lot for your advice here - I was not aware of this tool. I have used it with the following successfull change of IP address range in the ESP-adapter configuration:
image

My first try was actually to directly access the sqlite3 DB using the shell, but I think the shell access has been taken away for security reasons. Just writing sqlite3 in the terminal should normally start the sqlite3 shell, but it shows to be an unknown bash command.

After making a service restart by:
$ sudo systemctl restart mozilla-iot-gateway.service

And adding the ESP-adapter again in the frontend application, I can see that at least there is a try to connect to my ESP-01 unit:

image

But still with no success - I will check the .ino file again for any possible mistakes.

To be continued …

According to this post, it looks like the gateway will feature Add Thing by URL on coming release 0.4.0.

@rei_vilo, thank you, I look forward to that :slight_smile:

You should be able to install sqlite3 by doing:

sudo apt install sqlite3

As of Wednesday, Dave successfully updated the http-on-off-wifi101 example code for a SAMW25 Atmel dev board (also works on MKR1000 Arduino board) to talk to an updated http-on-off-adapter running on the gateway. Both repo’s are in github/mozilla-iot. For that example to work I first ran a program to setup the Wi-Fi configuration on the SAMW25, then I ran Dave’s example code that advertised the board via mDNS. The next challenge for that example will be to convert it from just using /H and /L (orig code example) to instead act as a native web thing type. That is, have it advertise itself as an “onOffLight” to control the LED_BUILTIN state. That could be a “Hello World” or “Arduino Blink” type of test program for checking out control of a thing via the gateway. If anyone wants to make the change to a native onOffLight type, feel free…

I’m excited to see what new things you all will create once the “add thing by url” capability is fully in place (via 0.4 release GUI).

kathy

1 Like

The sketch at https://github.com/mozilla-iot/http-on-off-wifi101 no longer builds on the standard Arduino IDE.

The culprit seems to be the change introduced by Remove ArduinoMDNS in favour of using PlatformIO one. (#5).

Please ensure the examples provided work with standard tools.

Also reported at https://github.com/mozilla-iot/http-on-off-wifi101/issues/6

Here are the steps I used to get the ESP(8266) working with mDNS discovery (no need for ‘add thing by URL’). :grinning:

Start with this adapter on the gateway:

You will need to follow the manual installation instructions shown as it isn’t built-in. Before you restart the server, edit one line as the ESP8266mDNS library doesn’t support subtypes as far as I can tell.

In the function “startDNSDiscovery(adapter)”, change the ‘Service Type’ to “_webthing._tcp” (from “_http._tcp,webthing”).

(Hopefully this adapter with this or similar mDNS mod can find its way into 0.4.0! It would make the experience so much more enjoyable…)

On the ESP, use this sketch. It is very clean and readable:

Here you’ll need to make corresponding additions/changes to mDNS to be compatible with the above adapter:

After the line “MDNS.begin(your-device-name) {”, add these two lines:

MDNS.addService("webthing", "tcp", 80); 
MDNS.addServiceTxt("webthing", "tcp", "url", "http://your-device-name.local");

The two ‘your-device-name’ occurrences above must be identical.

Run your sketch (I tested on both a Wemos D1 Mini and Adafruit Huzzah), restart the server as documented, enable the adapter, press “+” in the things screen, and it should come right up. Hit ‘save’, then ‘done’ and enjoy!

From here on, you should be able to change your thing easily in your sketch using just the WoT API.

Nice work Mike! I was just hacking on this earlier today. The thing-url-adapter is exactly what we’re using for the Add Thing by URL feature in 0.4.0. Your use of _webthing._tcp is interesting. The adapter expects _webthing._sub._http._tcp which is an http service with a subtype of webthing. We thought this was more semantically correct, but as you and I both found out the ESP8266’s mDNS library doesn’t support subtypes. I’ll file an issue on the thing-url-adapter repo to discuss if we want to support or switch to a subtype-less service identifier. I encourage you to share your thoughts on it!

Thanks, James for the hyper-fast reply! Let me know what you conclude. I am very happy to support whatever solution you come up with - just let me know. Happy to help in any way I can. I am very supportive of this project…

@hobinjk, I think it is of main interest to this Thing project that the ESP8266 is supported directly out-of-the-box, because the ESP8266 series is by far the cheapest IoT device and with full arduino support for programming it is easy as well. The ESP-01 on eBay can be purchased for 2-3 USD and I think this will cover most IoT devices, since the principle is one function per device and then make the logic by rules in the Thing web application. I hope that the Rules option will develop into more advanced options by time. Thanks a lot for your efforts …

I think (based on discussions with the WoT team) that we are on the same page here. Stay tuned… :wink:

The “thing-url-adapter” repository has been updated, so no more edits needed after installing on the gateway.

The mDNS detection method changed a bit from how I did it above. So now, the “esp8266-wot” sketch mDNS setup should look like this:

  if (MDNS.begin("esp8266")) {
    MDNS.addService("http", "tcp", 80);
    MDNS.addServiceTxt("http", "tcp", "url", "http://esp8266.local");
    MDNS.addServiceTxt("http", "tcp", "webthing", "true");
    Serial.println("MDNS responder started");
  }

Tested this just now and it works like a charm.