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

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"

Related

specifying connection on ESP8266 with AP and STA modes

I want to try to set up an ESP8266 (using the Arduino IDE) to occasionally connect to a wifi SSID to send telemetry back. I also would really like to be able to have it running a softAP for configuration/settings purposes. (i.e. so if you want to change internal settings in your code, you can connect directly to the device to access a web form to do so)
The problem is, I am not 100% sure how I know which is which when making an outgoing telemetry json query. I want it to go out on the STATION mode connection. Presumably in most cases the AP mode won't be connected, but there may be rare instances where both are connected at the same time. Thus how do I tell the device to specifically use the STA side of things when it needs to send data back over the internet?
I can't even seem to find any specific examples to ask if one or the other is connected. (you can poll WiFi.status() but - which one is it reporting?)
Any help is appreciated

How to find nodemcu (esp8266 + arduino) with dynamic IP (DHCP)?

I would like to connect the nodemcu to some LEDs, running a HTTP server (RESTful presumably) and turn on/off accordingly. However, how can the devices in the same network find the device? I guess I could try static IP for esp8266, but that is not guarantee to work every time everywhere. So how can I scan the network to find that, or is there any better solution?
I think most people use multicast DNS (mdns) for this, a quick Google should give you some examples for the environment you use :)
I like using MQTT, which is a different protocol that uses a central broker, but it's probably not quite what you want.
Also, why would a fixed IP not work? Most routers allow to assign one based on MAC address, which should work consistently.
And finally, you should be able to set a hostname for the ESP (wifi_station_set_hostname in the ESP SDK, which I think you can call from Arduino also), which should make it known with your router under that name.
I set my DHCP server to always give the same IP address to my NodeMCUs based on their MAC addresses. They are also configured with mDNS but I don't have mDNS on my Android phone so it didn't help me.

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

Is it possible to determine what jack on a switch a computer is connected to?

Is it possible to determine programmatically what jack on a network switch a computer is connected to?
It's either possible or not possible, depending on the switch.
If it's a managed switch, you could query its management interface to determine the MAC addresses behind each port. Then you could match that up with the hardware address on the computer you're interested in.
Some switches have discovery protocols (such as CDP or LLDP) which will broadcast the port's identity to whichever devices are attached. You could sniff the network for these packets to determine the port your computer is connected to.
You can try disonnecting them one by one and each time testing if the network connection goes down.
To identify switch port connected to your pc ; you need to manually access the switch and remove ur rj-45 cable so you can visualize any port having state of disconnection.. dm gui can be used if switch is managable
cdp and lldp wont work for pc as it doesnt support it

Peer-to-peer chat

im wondering if it's possible to create p2p chat application without server(so there is no need in external static ip.Is it true?)?
EddieC is right if the computers are located inside the same sub-network (LAN) or if the computers'ip is their interface to the Internet (WAN public ip). In that case, you can just use the ip's and ports directly.
However, usually, knowing the computers ip is not enough because the machines are located behind routers inside sub-networks. Thus, because the computers are hidden behind the routers, you will have to configure the routers to foward the packets to the right computers as function of the ports used.
Have a look at : http://wiki.vuze.com/w/Port_forwarding
If you do not want to use ip's because they are dynamic, you can configure urls with Dynamic DNS services.
Good luck
It is possible. But you must have someway for one computer to tell the other computer what their IP number is. You could email it to your friend or call them on the phone or post it on a message board.
If this program only has to work on a local network (LAN), there is something called broadcasting which might be of interest to you. It allows a packet to be sent out to every device on the network without having to know their IPs (then other instances of your program could reply with the IP of their machines so you could set up proper connections).
This won't work over the internet, though (imagine being able to broadcast to every computer connected to the internet!).

Resources