How to switch connection between cloud and local network in ESP8266 - arduino

I would like to understand it is possible to switch the ESP8266 connection between the cloud and WiFi LAN.
There are two paths to control the sonoff switch, connected to a wifi router. In case the phone is connected to the router, Path 1 acts as LAN network and ESP8266 can be controlled even without internet. In case I am not at home and would like to control the switch remotely via cloud, path 2 would be followed. Thus, I could get the best of both worlds.
From all the examples that i have seen so far ESP8266 could be operated in only one mode at one point of time, either Lan or cloud (both via the WiFi router).
So kindly help me with the switching code/logic, that will wait to work upon the commands provided via LAN mode if there are none left. Now it should work upon the instructions after switching to cloud mode and finally return to LAN mode after sometime and so on.

For security reasons your Sonoff device should not be reachable from the internet directly - ever. It should only be accessible within your local (home) network. That's your path 1.
To enable path 2 - without affecting the Sonoff device at all - you need a way to build a VPN from your smartphone to your local network. For the node it will look like all traffic is coming from your local network even though you are actually connecting into it from remote.
A fairly simple and cost-effective way to achieve this is to run PiVPN on a Raspberry Pi. See e.g. this video for instructions: https://www.youtube.com/watch?v=15VjDVCISj0

Related

How to send data between two ESP32's over same LAN?

I want to send data(I think I can achieve it sending http requests) between two ESP's that are connected to the same LAN. I don't want to use one as an access point! I have one esp that is acting as a homekit device, and I want to send data(for example, sensor readings) to it from another esp. I've seen many tutorials where one device is acting as an access point, but that's not what I need. I also don't really need to access the esp data directly from my laptop, so I believe I don't need the html page. I would appreciate any help, code, or any existing tutorials, because I didn't find a single one.
Configuring one ESP as an AP is only done for convenience. You can configure both of them in STA (station) mode and they will connect to, e.g. your phone hotspot or your wifi router.
Connected to the same hotspot, they are on the same network, and they will be able to communicate with each other (unless the hotspot is configured to not allow this ... ). The tricky part will most likely be for the "client" to determine the IP address of the "server" in order to create the connection.
If you have admin access to the hotspot, you can cheat and hard code the IP addresses (assuming that the hotspot will assign the same IP address to the device the next time it sees it.)
It's also not difficult to use mdns (aka bonjour), which allows a network device to assign itself a local hostname. So you can name one ESP ("myserver") which allows the ESP running the client code to connect to "http://myserver.local"

Connecting to a wifi network while acting as an access point

I have a raspberry pi (model 3 B+) acting as a wireless access point. I would like the pi to be able to connect to an available wifi network while remaining a wireless access point.
The use case for this would be as follows:
Connect to the access point from a laptop
From the laptop, navigate to pi_ip_address:port in a browser
From the browser, a list of available networks would be shown
From the browser, select an option and enter the password
From the Pi, connect to the selected network
Is this possible? If so, has anyone had success doing this and/or is there documentation available?
Thanks in advance

How to extend Sony Remote Camera API access point range?

Just for reference the Sony Remote Camera API only works by using a 1:1 Wifi Connection
The Wifi signal strength of my Sony DSC-HX60V camera already drops after a few meters distance. But I want to be able to remotely control the camera over a range of 50 meter. There is no way that the onboard Wifi can achieve this range.
So now Iam looking for a solution to this problem. If it helps a local Wifi router exists that covers the whole range:
A normal Wifi repeater seems to be the best option, but according to a Forum Post using a repeater does not work, because the repeater acts a client and the camera can only connect to one client at the same time. Did someone got it to work with a repeater?
Additionaly I was thinking about using a Raspberry Pi with a second Wifi adapter that connect to the local Wifi and manages the API requests.
Any other ideas?
Disclaimer:
Even tho this Question may be more Hardware and Network related and thereby fits more into the SuperUser Network. A working Network connection does not necessary imply that the API is working aswell. This is why I posted this Question here
If you have a router which can work in 'client mode' that should be able to make a 1:1 connection with the camera, and then present that link over ethernet - you may have issues with network addresses and/or discovery if your main network is a different IP range to what the camera offers/DHCP's.
Some of the Sony cameras support 'multi-wifi' where the camera connects to an external device (normally the LiveViewRemote, but can be a router). Unfortunately the HX60 (and presumably any of the Play Memories SmartRemote app based ones) does not seem capable of this.... maybe the QX1 is an exception as it's supposed to work like this.
This connection connection is managed via WPS, and once connected the RemoteAPI works well. Works for my AS100.
If you are looking to set up a RaspPi, I can confirm that it works with this Python library:
https://github.com/Bloodevil/sony_camera_api
https://www.youtube.com/watch?v=xR3gAfu4Hfw

Forwarding data from server to router to Arduino

Basically I have an Arduino UNO that I have connected via Ethernet to my router. I have logged the IP with my server and I would like to push data to my arduino. I guess the flow of data would be to send data (not sure the best way? Should I just open up a port and stream the data?) to the router that then forwards it to my Arduino at a local address assigned by my router.
How can I tell the router to forward this information on without logging in and changing anything with the router. The point of this exercise is to do everything with code and not do any other activities like logging into the router and setting things up. I want to do this as I have my Arduino recording temperature and I want to push data to state if it should switch sending the data from degrees or Fahrenheit or visa versa.
I would use a socket server with a publish/subscribe pattern. Probably several out there but I know XSockets.NET best.
A few hours ago I actually connected my Arduino to XSockets and communicated between webpages and my arduino both ways.
I will put the code on github when I am done, but you can look at a video showing the concept here: The Stuff For You Starts At 3:20
You dont need to open any ports as long as your arduino and server is on the same local network. Since IP adresses maps all devices on a network including your arduino.
The reason you want to open ports on your router is to make people outside your local network access a server on your network. Reasons why port forwarding exists is that when someone sends a packet of data to your public IP (which is your router) it doesent know which local IP to send the packet to. It then discards it, unless you port forward a port to a local IP, which means your router sends all packets with that port to that local IP adress.
You also need to make your own server program, for example a java program to act as a server.
I made something similar to what you are looking for, but i use a wifi shield instead. I've had some problems with maintaining connections with it, but so far it seems that it's a problem with the wifi libary.
You still might learn something from it though:
Maintaining communication between Arduino and Java program
If you want to know more about how the java server works in general, here is a great tutorial which explains a lot of the basics:
http://www.thenewboston.org/watch.php?cat=25&number=38

How is chromecast initially discovered before even connecting to wifi?

How is chromecast initially discovered before even connecting to wifi? What is the underlying technology?
Is it done using multicast if so will a device get an ip before providing wifi password to send multicast
https://superuser.com/questions/626199/how-does-google-chromecast-connect-to-secured-wifi
Chromecast acts as an access point when first turned on. The software you install software on your andriod, windows or mac device will find it and connect to the chromecast's AP directly. Then the chromecast scans for access points allowing you to pick one and enter in your password. Once this is done, it will connect to that access point instead of acting as it's own access point.

Resources