• How could I implement web service that can be found with bonjour?

  • To my understanding, bonjour/zeroconf is the notion that one can find the IP address of a device on a TCP/IP network using "multicast DNS". The idea being that the device may have a dynamic IP address obtained through DHCP but we have client applications that wish to connect to it. Since it doesn't have a static IP address, we need a mechanism to determine its IP address at runtime. Multicast DNS allows a client to broadcast a request to locate a specific named device. If ESP8266 supported multicast DNS (which it does), then it would determine that a request to locate it was being made and it would broadcast a response with its own current IP address. This would be received by the original requestor (and as a side effect .. possibly other devices) and a normal TCP/IP connection could progress.

    While the raw ESP8266 provides support for multicast DNS, I can't remember whether or not that was exposed through Espruino. If it was, then we are good to go. If it wasn't, then a change request would have to be made through Github to see if it could be added.

    As for implementing a Web Service, I'm am assuming you mean a REST client or server ... using JSON over an HTTP request. That can be achieved using Espruino today.

  • Yes, exactly.
    My goal is to make Espruino to act as a minimalistic web service that responds to HTTP rrquest with the analog sensor values as Json. Since DHCP is needed in order to avoid hard coding the IP, the bonjour is needed on the client side to find the sercvice ip. Because the device would be headless (no screen or other means to set config), in this way any need to pre-config could be avoided - just plug and play assuming there is DHCP service in the network.

    Hmm. That would work with Ethernet but WiFi requires still SSID and pw to connect.. Could that be avoided somehow too?

  • Once the ESP is connected to the network, a wifi.save() stored the ssid and pwd in EPROM- it will auto connect net boot.

    The workaround if mDns is not available then you can add the Mac address to your router and use the deco reservation, so tht it gets a known ip. Then you can set the hostname in the wifi init, and any browser can refer to the ESP by hostname.

  • @Kolban and @Wilberforce, @user68159 is talking about using Espruino on a Pico with an ESP8266 running the AT command firmware - so I'm not sure some of the stuff you're suggesting applies here (eg wifi.save())

    At the moment Espruino doesn't natively provide UDP support, so it'd be tricky to implement something like Bonjour (especially when using ESP8266 as a separate module). It might be possible to hack something up by communicating directly with the ESP8266 module to send UDP packets (if someone had some example code of doing DNS on something like an Arduino then we could probably port it across though).

    As suggested, setting up the router to allocate specific IPs/names would be by far the easiest way forward though I think.

    Otherwise you could make it request a webpage from a server every so often - which would allow you to figure out its IP?

    WiFi requires still SSID and pw to connect.. Could that be avoided somehow too?

    The ESP8266 can be an access point - so you could make it appear as an access point that you can connect to and set the WiFi info with (and it could then go and connect itself)?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

How to do Bonjour / zeroconf with ESP8266 and Espruino Pico?

Posted by Avatar for samppa @samppa