[withdrawn]

Deleted <20 characters>

7 Likes

How do you enter MAC address? Just as a hex string?

Thanks. Are you saying that the hub is always listening on TCP port 39500? I can see it in the hub status (localSrvPortTCP: 39500). The question is if it ever changes or not.

1 Like

Awesome! I’ve the answer in another thread, btw. :smile: I don’t think it worked in V1 because I’m pretty sure I’ve tried everything 6 month ago and gave up.

What size resistors do you need for pullup?

Thanks.

@Charles_Schwer you are AWESOME! With very little screwing about I now have a < $2 device on my WiFi talking to SmartThings. Ubiquitous, cheap sensors are now possible with a little bit of hacking and with the help of your code here.

I’ll be watching this thread with hopes that relays are figured out, as that opens a whole new world for ST-enabling devices around my house.

edit: Here’s what it looks like using your stock application. Latency is on the order of 1 second - not bad!

Excellent! I sat down to do research on doing a PIR + ESP8266 motion/occupancy sensor and found your thread. Your work will allow me to do that really quickly. I want to make a device without hard coded settings if possible. So I’m looking to config the ESP on first-boot setting its wifi SSID and key using this code: https://github.com/tzapu/WiFiManager. I’m also going to try to figure out how to get SSDP ( https://goo.gl/YFXvaX ) and a service manager working too so it would make it so the hub IP and port aren’t hard coded as well. That would be the perfect slam dunk for easy to setup, really cheap WiFi based sensors.
Awesome work!

3 Likes

As someone who has never touched an arduino, please let me say that quote is a little bit underestimating the bar to using this hardware.

Could someone with good documentation skills and a kind heart please write up how to do this for those of us who don’t solder for fun, who don’t run Linux and who want things to Just Work? Start with URLs to purchase the actual hardware necessary.

[quote=“mdawson, post:12, topic:36906, full:true”]
As someone who has never touched an arduino, please let me say that quote is a little bit underestimating the bar to using this hardware.[/quote]

I totally understand where you’re coming from on this. For a complete beginner, you might find these sort of projects to be a tough hill to climb as it assumes quite a lot from the user. The Arduino is probably the easiest thing to dive into, but even that will require some basic knowledge of digital circuit design. The good news is that there are several Arduino kits and books and tutorial series available that could get you started. It is a mature and robust platform, and is far better suited to a beginning user. The good news is that almost everything you learn there will be directly applicable to similar systems like the ESP8266.

If you want to jump straight into the ESP8266 environment, you might have better luck with a NodeMCU board which would at least save you from having to hook up all this crap just to get a program flashed onto this chip:

The reality is that the ESP8266 is a relatively new device with sketchy documentation loosely translated from Chinese by community hackers. Things change very quickly and as time goes on better tools and devices are being developed for interfacing with it. Still, you’re going to need to learn at least a little bit about digital circuits before any of this is going to be of much use. My recommendation would be to get an Arduino kit, learn the basics, then use that to push forward into more esoteric systems like the ESP8266.

I know how to solder, but don’t know a damn thing about circuit design. Can’t I just buy these things already in pieces that plug into each other? I’m not looking for the satisfaction of building one. I’m looking for the satisfaction of it working.

This has the potential to monitor any kind of open/closure, right? I could just wire it to a physical dry switch, yes?

The circuit design thing is a key problem. Soldering is handy, but the core issue is knowing things like what a pull-up (or down) resistor does and when/why you’d use one. If you really want to start hacking at microcontrollers, you’re likely going to want to get these concepts sorted out in an environment that is easy to learn on. The Arduino has the singular advantage of being well-established with zillions of books and tutorials available to help guide you down that path.

I’d strongly recommend against ESP8266 as a beginning-level tool for learning digital circuits. You can do it, but you’ll find the Arduino ecosystem an easier path to getting the fundamentals out of the way.

If you insist upon jumping straight into the ESP8266, you’re going to have a much better time with an integrated dev unit like the NodeMCU. This would be the beginning-level ESP8266 platform that would simplify hooking into your PC for development work. There have even been a handful of books published in the last few months to help get you started.

[quote=“mdawson, post:14, topic:36906, full:true”]
Can’t I just buy these things already in pieces that plug into each other? I’m not looking for the satisfaction of building one. I’m looking for the satisfaction of it working.[/quote]

Good news on this part: yes you can.

3 Likes

Anyway, back on topic:

While we’re posting a wish list, web OTA updates of the ESP8266 is now possible and would be super-handy to include in the sketch if there’s room. Once I get this soldered into place it’s going to be much easier to update code over the network vs, trying to get a serial programmer wedged in there.

I found this website quite useful - you might want to spring for a more integrated board first in order to limit the amount of wiring of standard components required…

2 Likes

[quote=“BenGeek, post:11, topic:36906, full:true”]
So I’m looking to config the ESP on first-boot setting its wifi SSID and key using this code: https://github.com/tzapu/WiFiManager. I’m also going to try to figure out how to get SSDP ( https://goo.gl/YFXvaX ) and a service manager working too so it would make it so the hub IP and port aren’t hard coded as well.[/quote]

Based on your suggestion I’ve got the skeleton of a working WiFiManager application running with aREST to send and receive REST commands. I need to get cranking on the ST end of things before release, but it’s worth noting that WiFiManager is a bit of a bear to get running. The current release versions of WiFiManager and the ESP8266 Arduino integration don’t work well together until you get off the stable releases which takes some hacking. Also, the result consumes 74% of my ESP-01’s flash leaving little room for much else. I’m going to keep hacking at this and post some results here (hopefully), but it’s going to be difficult to get people started up as you need to do a bunch of manual setup just to get the build environment together as the standard Board Manager and Libraries available through the Arduino IDE aren’t up-to-date enough to get everything going.

Thanks for the tip and I’ll post more results when (if?) I get there.

Wow, didn’t realize that code was such a bear. Way to go getting it to work though! I’m waiting on another set of esp’s to arrive before I can start testing some of this out. I had assumed the wifi manager was kind of the “last thing” as I was going to focus on the SSDP discovery first. Let me know how things go. I’ll share anything I get working with SSDP once my package arrives from Adafruit. I’m very excited about the concept of creating a whole set of tutorials to create esp based sensors and widgets etc.

1 Like

You don’t actually need a separate pull-up resistor. You could just use

pinMode(2, INPUT_PULLUP);

And connect the other side to ground (works for me).[quote=“luma, post:21, topic:36906”]

The current release versions of WiFiManager and the ESP8266 Arduino integration don’t work well together until you get off the stable releases which takes some hacking […]
[/quote]

I didn’t have any issues at all - just the stock released versions (ESP 2.0.0 installed via board manager link and WiFiManager 0.9.0 installed via the Library Manager) and everything works fine - only added:

#include <WiFiManager.h>
[…]
void configModeCallback (WiFiManager *myWiFiManager) {
  Serial.println(F("Entered config mode"));
  Serial.println(WiFi.softAPIP());
  Serial.println(myWiFiManager->getConfigPortalSSID());
}
[…]

void setup() {
  […]
  WiFiManager wifiManager;
  wifiManager.setAPCallback(configModeCallback);
  if (!wifiManager.autoConnect()) {
    Serial.println(F("Failed to connect to WiFi and hit timeout"));
    // reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(1000);
  }
  […]
}

and everything "just works"™ (I am using a NodeMCU 1.0 ESP-12E board in case that matters).

For me device (chicken coop door controller) I decided to use ArduinoJson and I added an /updateSettings endpoint which submits settings via POST as JSON - I no longer have any settings hardcoded in the sketch! This also allows to update the hub IP:port in case they change (e.g., keeping track of them in state variables of the device).

Still trying to see whether I can have the device handler automatically update the MAC so you don’t have to type that in (settings the initial deviceNetworkId as hex IP:port and then using the value returned in msg.mac for the initial parse response - manually typing a MAC address is tedious and error prone…

@Charles_Schwer: Thanks again for a great starting point to hack away at! :beers:

1 Like

In my testing I couldn’t get the example code “AutoConnectWithFSParameters.ino” to work until I updated the Arduino ESP8266 library to 2.1beta and the same behavior has been seen by others. Although there’s no mention there of an update fixing the issue a similar problem existed in .7 which required running on 2.1 however that appears to be fixed now. So maybe just WiFiManager 0.9 and the stock 2.0 release of ESP8266?

The complexity of getting the build environment right has given me a new found appreciation for the more simplistic approach used by @Charles_Schwer. As it is I feel like I’m forcing the user to do a bunch of manual configuration to the build environment to save some manual configuration in the code.

With the update I am able to use that demo code to boot into AP mode, then prompt the user for device IP address details along with providing the ST hub details too. Here’s what it looks like:

This works if you can be 100% sure that the hub’s IP and port will never change - even with potential future FW upgrades to the hub. Being able to send the configuration dynamically solves this issue as the device handler can check for changes to the hub’s IP and port and automatically reconfigure the device on the fly so that messages pushed from the device still make it to the hub.

I just added OTA to me device as well and that is another reason to allow the hub/device type update the device. Rather than using the default (eps-|address|) name for the OTA server you could have the OTA server report the device name that it has on your hub. Once you deploy multiple of these devices you want to be able to keep track of which one is which and don’t need different code for each one of them.

I’ll see whether I can incorporate all my changes back into this device type and send a pull request.

1 Like

I updated both the sketch and the device type to no longer require any hard coded settings - see pull request.

Please note that the OTA updates don’t seem to work for me at the moment (the ESP crashes after accepting the password) - this is with the 2.0.0 ESP release. Hopefully this will resolve itself with the upcoming 2.1.0 which has some changes to the OTA code…

After updating the settings in the app you need to hit refresh to fully initialize/update the device - I haven’t spend time to figure out whether this could be incorporated into the settings update as well.

1 Like