Hi, I was trying to get my Arduino to connect to my laptop through python socket but so far no success yet.
Here's my Arduino code:
#include <SPI.h>
#include <WiFiNINA.h>
char ssid[] = "iPhone";
char pass[] = "00000000";
int status = WL_IDLE_STATUS;
IPAddress server(129,127,237,229);
WiFiClient client;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
status = WiFi.begin(ssid, pass);
if (status != WL_CONNECTED) {
while (true) {
Serial.println(" No Wifi !");
delay(1000);
}
} else {
Serial.println(" YES WIFI!!! ");
Serial.println("Now connecting to laptop.");
if (client.connect(server, 1234)) {
while (1) {
Serial.println("I'm innnnnnnnnnn!");
delay(1000);
}
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}
Here's my Python code:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 1234)) # bind(ip, port)
print("Done binding.")
s.listen(5)
while True:
clientsocket, address = s.accept()
print(f"Connection from {address} has been established!")
I got the Arduino to connect to my iPhone WiFi but not to my laptop through socket.
The IP address I use in the Arduino code (129,127,237,229) is the one I use google to find (googled what's my IP address and Google said it's that number). Am I missing something critical here?
Thanks!