Quick question...
Can the ESP32 AsyncWebServer port be set/reset AFTER the server has been declared?
The server is declared after the global variables, but before any functions, with the line:
AsyncWebServer server(PortNumber);
Usually, the port number is 80 (the default HTTP port).
However, I have the need to use a different port and the port will be chosen by the user from a WiFi credentials page and then stored in NVS.
So, I need to retrieve the port number from the NVS before I execute the AsyncWebServer command, or be able to change the port number on the fly.
How can I achieve this?
Looking at the ESPAsyncWebserver declaration there doesn't seem to be a way to change or set the port after creating an instance of it. But isn't the solution to your problem as simple as creating the server later, after your configuration settings have been read? Something to this tune:
uint16_t port = config.read("server_port");
ESPAsyncWebserver* server = new ESPAsyncWebserver(port);
The answer to this is here: Answer
Related
I am using WinAPI to tinker with RS232 ports. Using SetCommState function I've set fRtsControl: RTS_CONTROL_HANDSHAKE and fDtrControl: DTR_CONTROL_HANDSHAKE, so from my understanding both DTR/RTS handshakes are now enabled, and now additionaly I need to set fOutxDsrFlow and fOutxCtsFlow to true, to make this flow work, right?
Having it all set up how can I manually change DSR/CTS to high/low, so I can see what happens?
Or perhaps are RTS/DTR handshakes and DSR/CTS signals completely separate things and I am understanding it incorrectly?
The DSR/CTS signal has only a passive function of acquiring the state or notifying the change as an event.
If you want to actively control it, you need to prepare another hardware or software for it and use another interface independent of the target serial port.
It's relatively easy to have two virtual COM port device drivers with loopback or port-to-port connectivity.
For example, in the case of software, there is something like this.
Connecting to serial port (com port) over network
The same thing is to prepare two USB serial port dongles in terms of hardware and connect them with a cable that crosses DTR/DSR and RTS/CTS.
Both need to be programmed to test the target port/software and run on the opposing port.
I need to know the IP address of ESP32 on the local network(without printing ip on serial monitor ). The idea is to do mDNS or UDP broadcast to send the IP to the android application. The app will then use that IP to do the communication. Is there someone who has already done it?
Maybe a bit late, but nevertheless:
The function called "tcpip_adapter_get_ip_info" can be used to obtain your interface IP address, netmask and gateway. You can pass in TCPIP_ADAPTERE_IF_STA to get the information you desire.
#include <tcpip_adapter.h>
tcpip_adapter_ip_info_t ipInfo;
char str[256];
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
sprintf(str, "%x", ipInfo.ip.addr);
Note that it is also given in the event handler:
case SYSTEM_EVENT_STA_GOT_IP:
eprintf(eLOG_EVENTQ,"IP: %s\r\n",
ip4addr_ntoa(&event>event_info.got_ip.ip_info.ip));
If you're looking to identify your ESP32 easily on the local network, you can simply use the mDNS service.
This will make your ESP32 accessible via user friendly hostname.
Example: myesp32.local
I wonder if I can use TCP connection protocol or something similar to it to convert IP to Address name
ex:
192.168.1.10:8080 //convert this ip to for example >>
my.localpc.com // or thomething looks like this
so Where I can start from
I like if suggestions related to these lang.s (C# , Python , C++ , MATLAB)
here is the story
"..
I was building an ROV for a competition and I used TCP IP to transfer date from PC to Raspberry PI but the IP always changes whatever I use fixed IP sometimes I have to change the TCP port then I'll change the port on the client program as well , so I asked myself if there is a way to call the ROV like http\myROV.com .. instead of 192.168.1.5:8080 .. which may change on several situations "
Thank you
Anything that can access normal sockets functions directly should be able to use gethostbyaddr or gethostinfo.
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
I am programming a server and client program to communicate between a windows PC using the Boost libraries and a Linux ARM beagleboard using the asio stand alone libraries. I have for a while had successful UDP communication between the two devices but now I want to recover the port from the endpoint the server discovers when the client connects. The way the client connects is via query:
udp::resolver resolver(io_service);
udp::resolver::query query_tx(udp::v4(), hostIP, "43210");
udp::endpoint receiver_endpoint_tx = *resolver.resolve(query_tx);
where host IP is a string and this works fine. Upon debugging though I notice that when i check the value returned by:
receiver_endpoint_tx.port()
This returns 51880. Now don't jump the guns and yell out network byte order and host byte order. I AM AWARE. The strange part is that this number 51880 sometimes is a different number and when i check what the server has stored in its endpoint it is a completely different number: 21743. Now I know I must be doing something wrong with the byte orders but i tried:
//unsigned long port_long = boost::asio::detail::socket_ops::host_to_network_long(receiver_endpoint_tx.port());
//unsigned long port_short = boost::asio::detail::socket_ops::host_to_network_short(receiver_endpoint_tx.port());
And they do not give me back my original port: 43210. Neither does network to host. So what am i missing and how can I on both ends recover my 43210 port? Obviously it must be there somewhere because they are successfully communicating.
Thanks in advance, sorry if noob mistake :)
Fistly, UDP is connectionless, there is no connection.
I'm not sure if I understand you correctly, but it sound too me like you want to bind to specific port numbers. If you want the client to send a packet from port x to port y on the server, and the server should respond from port y to port x, then you need to bind the sockets to the desired ports. Alternatively you can use the constructor to bind. Not doing so will result in the OS using ephemeral ports.
Further, to get the remote endpoint that a packet was received from the async_receive_from takes the sender_endpoint reference parameter. When the read handler is called, you can retrieve host and port from it.