Hello everyone! I am new to arduinos and the arduino IDE, I do have years of programming knowledge behind me and I am developing a program with the UNO R4 WIFI board. I am wanting to send heart rate/pulse data to a remote python script that will send data into VRChat for a 3D avatar's pulsating glow effect. The connections needed are mostly there. However, I am having trouble connecting the arduino to a domain IP address via TCP communication. I have tried both HTTP and TCP and I have gotten NOTHING to connect to my domain IP from the arduino. The arduino can connect to the internet strangely enough though. The hosting software that acts as an API gateway for my program is ngrok. I have done projects with python in the past using the same setup with ngrok and have not had issues. I can only reason something is wrong on the arduino side. I have copy and pasted official arduino sample code and have run it and it still has not worked. No dependency issues either, just the script does not connect and I do not know why... I have pictures of my ngrok setup and the code that is in my sketch in the arduino IDE. Would anybody know at all what to do or what I am incorrectly doing? Thank you all for your time!
const char* WIFI_SSID = "SSID"; // CHANGE TO YOUR WIFI
const char* WIFI_PASSWORD = "PASSWORD"; // CHANGE TO YOUR WIFI
const char* TCP_SERVER_ADDR = "0.tcp.ngrok.io"; // CHANGE TO TCP SERVER'S IP ADDRESS
const int TCP_SERVER_PORT = 12865;
WiFiClient TCP_client;
void setup() {
Serial.begin(115200);
while (!(Serial)){
;
}
Serial.println("Arduino: TCP CLIENT");
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true)
;
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
Serial.print("Attempting to connect to SSID: ");
Serial.println(WIFI_SSID);
// attempt to connect to WiFi network:
int status = 0;
status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (status == 0) {
delay(1000); // wait 10 seconds for connection:
status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}
Serial.print("Connected to WiFi ");
Serial.println(WIFI_SSID);
// connect to TCP server
if (TCP_client.connect(TCP_SERVER_ADDR, TCP_SERVER_PORT)) {
Serial.println("Connected to TCP server");
TCP_client.write("Hello!"); // send to TCP Server
TCP_client.flush();
} else {
Serial.println("Failed to connect to TCP server");
}
}
void loop() {
// Read data from server and print them to Serial
if (TCP_client.available()) {
char c = TCP_client.read();
Serial.print(c);
}
if (!TCP_client.connected()) {
Serial.println("Connection is disconnected");
TCP_client.stop();
// reconnect to TCP server
if (TCP_client.connect(TCP_SERVER_ADDR, TCP_SERVER_PORT)) {
Serial.println("Reconnected to TCP server");
TCP_client.write("Hello!"); // send to TCP Server
TCP_client.flush();
} else {
Serial.println("Failed to reconnect to TCP server");
delay(1000);
}
}
}
