I have a device that put RS232 over ethernet(GW212). It works fine, and I can connect to the IP using putty to see the data. Would love to be able to read this data over wifi with a micro controller, I've tried the http.get examples with no luck. I'd appreciate anything pointing me in the right direction.
@2lowiq2code , welcome to the forum!
The GW212 device converts RS232 data to Ethernet protocols.
From your title it is evident that you intend to use an ESP32, but are you wanting the micro-controller to:
a) read the data from Ethernet and send over WiFi?
or
b) grab data directly from RS232 and send over WiFi? (I.e. a WiFi version of the GW212)
Welcome!
There are a lot of sketches posted here and on other forums that will do or with some modification do what you want. However, Please keep in mind that we are not a free design or code-writing service. We’re more than happy to help with your design or code, but we need you to make an initial attempt. Please design and write your code, then post it along with an annotated schematic and an explanation of what’s not working properly. There is also a for hire section if you want to pay for it.
- Show Your Work First: Before asking for assistance, make an attempt to design or write the code yourself. Share your work along with details about what isn’t working. That includes a preliminary schematic that you drew.
- Provide Clear Documentation: Since we can’t see your project, share an annotated schematic (best) or a clear drawing of your setup. Clear Pictures are welcome, but avoid using Fritzing diagrams as they are wiring diagrams, not schematics, and are not ideal for troubleshooting.
- Include Technical Details: If there is specific hardware involved, include links to technical information. There are often many versions of similar components, so precise details are essential. I will assume the processor is a UNO. Many times the processor is stated as ESP32, please state which one and post a link to it.
- Reference Resources: For additional help, check out useful links and tutorials: Useful Links on Arduino Forum. Of course one of the better sources of information (in my opinion) is the Arduino Cookbook. Skim it cover to cover and stop on any project that interests you.
I want to read the data over the wifi network that the GW212 serves to. When I connect to the IP using a laptop with putty on the same wifi I can read the data no problem. I have chosen an ESP32 for this project.
I'm using ESP32 Devkit1, this GW212 Atop GW212: 1-port RS-232. Rugged Metal Case. Easy Configuration
and this reference ESP32 HTTP GET and HTTP POST with Arduino IDE | Random Nerd Tutorials
I don't know if this is the right angle of approach or not.
Do you have to type anything in to putty or does it just show you the data your are expecting?
Assuming it just shows you the data, then what you need to do in the ESP32 code is create a TCP client and connect it to the GW212. From what you’ve said it has nothing to do with HTTP
Thank you my man, that was all I needed. Used this as a reference and I'm reading the data.
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
const char* serverAddress = "192.168.1.100"; // Remote server IP address
const uint16_t serverPort = 8080; // Remote server port
WiFiClient client; // Or EthernetClient client;
void setup() {
Serial.begin(115200);
// Connect to WiFi (or initialize Ethernet)
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to WiFi!");
}
void loop() {
if (!client.connected()) {
Serial.print("Connecting to server...");
if (client.connect(serverAddress, serverPort)) {
Serial.println("connected!");
// Send initial data to the server
client.println("Hello, Server!");
} else {
Serial.println("connection failed");
delay(5000); // Wait before retrying
return;
}
}
// Read data from the server
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print("Received: ");
Serial.println(line);
}
// Example: send data every 10 seconds
static unsigned long lastSendTime = 0;
if (millis() - lastSendTime > 10000) {
client.println("Sending periodic update");
lastSendTime = millis();
}
// If the server disconnects, the client will need to reconnect in the loop
if (!client.connected()) {
Serial.println("Server disconnected, stopping client.");
client.stop(); // Close the connection
}
}
This project is going to get done now, thanks for the help.
You need to run a Telnet server on ESP32, then you can connect to it with Putty. ESP32 can read RS232 and transmit the data as a Telnet server.
But if you are only interested in getting (reading) a stream of data via WiFi you can use a web server and implement websockets on your web page.