I have a node.js server in which I am trying to send data in real time from my raspberry pi pico w over sockets.
My Simple Server is setup as follows:
const express = require("express")
const app = express();
const http = require("http");
const { Server } = require("socket.io");
const cors = require("cors")
const server = http.createServer(app)
const io = new Server(server, {
cors: {
origin: "*",
}
})
io.on("connection", (socket) => {
console.log('User Connected: ${socket.id}');
})
app.get('/', function(req, res, next) {
res.send("Hello world");
});
server.listen(80, () => {
console.log("Server is running")
})
The code I am running on the client side on my Raspberry Pi Pico W is as follows:
import time
import socket
import network
ssid = '<name>'
password = '<password>'
# Just making our internet connection
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
# Wait for connect or fail
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
print('connected')
status = wlan.ifconfig()
print(wlan.ifconfig())
c = socket.socket()
c.connect(('http://127.0.0.1/',80))
print('Connected')
After ensuring the server is working just fine (i setup a react client and was able to transfer information), I am still unsure why my micropython-based client on my microcontroller cannot setup a socket. I keep getting the error:
Traceback (most recent call last):
File "<stdin>", line 32, in <module>
OSError: [Errno 103] ECONNABORTED
If someone could guide me on potential solutions that would be extremely helpful. Thanks!