Getting the Ethernet/ESP8266 gateway to act as client instead of server
-
Currently, it looks like the Ethernet/ESP8266 gateways open a socket and act as a server to accept incoming network connections. However, I'd like it to act as a client, and connect to a public host/port. Is this possible?
This is my use-case: I need to be able to control devices at home with a phone/web-based app, from anywhere in the world. To make this possible, I'll need to host the controller software on a public server on the Internet. If this controller has to access the gateway inside my home network, I'll have to do some jiggery-pokery at my router, and maybe configure a VPN. I could avoid the trouble if the gateway would act as a client and connect to the controller instead.
Even better if this was done using standard/expected open ports, rather than ports that might be blocked in different networks. So if the gateway could initiate a HTTP-based WebSocket connection to a controller based on the controller's public address, it would be perfect.
It appears that this is how the gateway connects to an MQTT broker, but I couldn't find any way to do this for the socket API. Is this possible?
-
-
Thanks, @mfalkvidd. That seems to only work for the MQTT gateway, though. I was wondering if there's something similar for the socket API, using just the Ethernet/ESP8266 gateways (without MQTT).
-
Enabling client mode is documented in the sketch here:
-
Client mode is what I was looking for, thanks, @hek.
Is it possible to define the controller IP address dynamically at runtime, rather than having it compiled into the sketch? That way, it could be possible to have some sort of API/UI to configure the gateway after deployment, without having to reflash the Arduino.
(I'm working off the development branch, if that's any help.)
-
No, but you can set an url instead (and control it via your/some dns): https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/core/MyGatewayTransportEthernet.cpp#L160
-
Cool. Doesn't quite do the job, but I'll figure my way around it. Thanks again, @hek.
-
This isn't what you're looking for, but whats stopping you hosting the controller in your own home and using a VPN or internet facing controller behind security or using a VPN on your phone?
i currently run Domoticz and have a Domain pointed at a Raspberry pi in my house. access outside the internal network requires a username and password, but recently i setup OpenVPN so that when connect to the VPN on my phone, i can use the Domoticz app or access the Domoticz web interface without having to setup Authentication.
-
@Adam-McCartney That certainly works. I'm looking to avoid the overhead of the configuration and setup required at home, and want to keep it simple for everyone to use ("just go to <url>"). There's also the interesting possibility of the hosted controller being used by more than one household, but that's something for the future.
-
Personally, i dont like the idea of my controller being on someone elses Box. I have all i need on the RPi. Plus, if my internet connection goes down, i can still turn my lights off!
Domoticz allows you to join up controllers so you can still have access to other controllers in other houses. Its worth having a look.
-
Hi, In the 3 post is there a link https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/GatewayESP8266/GatewayESP8266.ino#L104... The link is dead and i tried to find it, but with no luck... Can you post the new URL?
Regards,
Jan
-
@stofakiller Examples->MySensors->GatewayESP8266MQTTClient in the Arduino IDE or https://github.com/mysensors/MySensors/tree/development/examples/GatewayESP8266MQTTClient is what you are looking for I think (at least for MySensors 2)
Or GatewayESP8266 / https://github.com/mysensors/MySensors/tree/development/examples/GatewayESP8266 for the one without mqtt
-
Hi,
I have look at both of them... But my interest lies in the esp8266 as a client/node without NRF24L01, to eg switch a relay on/off... And it has to go through my Vera controller... I have been playing with Apples Homekit, Raspberry Pi and Vera, and now i can control my vera switches and dimmers with just my voice
Regards,
Jan
-
@stofakiller I think that is supported but I don't know how to do it. Hopefully someone else can chip in.