Trying to get “Hello, World!” printed on a server, so I can eventually send GPS coordinates. I’m using:
ZED-F9P → Sparkfun ESP32 Thing Plus C → iPhone personal hotspot → Python socket server.
Here’s the sketch I’m using on the ESP32:
#include <WiFi.h>
const char* ssid = "iPhone_name";
const char* password = "iPhone_personal_hotspot_password";
const char* server = "123.456.7.89";
const int port = 12345; // or whatever port your server is listening on
void setup() {
Serial.begin(115200);
// Set the WiFi mode to STA
WiFi.mode(WIFI_STA);
// Connect to the WiFi network
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("...");
}
Serial.println("Connected to WiFi");
// Connect to the server
Serial.println("Connecting to server...");
WiFiClient client;
if (!client.connect(server, port)) {
Serial.println("Connection failed!");
return;
}
Serial.println("Connected to server");
// Send "Hello, World!" to the server
Serial.println("Sending message...");
client.println("Hello, World!");
// Disconnect from the server
Serial.println("Disconnecting from server...");
client.stop();
Serial.println("Disconnected from server");
}
void loop() {
// This sketch doesn't do anything in the main loop
}
The last thing it prints in the IDE serial monitor is:
“Connecting to server…”
I get nothing in the server when using the iPhone hotspot, but it works when using my normal home WiFi router. This is the code I use for the server:
import socket
# Create a socket to listen for incoming connections
server_socket = socket.socket()
server_socket.bind(("", 12345))
server_socket.listen()
# Loop indefinitely to handle incoming connections
while True:
# Accept an incoming connection
client_socket, client_address = server_socket.accept()
# Receive the message from the client
message = client_socket.recv(1024)
# Print the received message
print("Received message:", message)
# Close the client socket
client_socket.close()
Using the iPhone hotspot prints nothing. Using the home WiFi router gives:
b’Hello, World!\r\n’
Any ideas for how to get this working with the iPhone personal hotspot would be appreciated! Thanks