I've stumbled upon a ERNOMEM error while trying to send data from two ESP8266 to PC through sockets. It happens ONLY when im sending data more than 5 times a second. One of ESP's is and access point that another esp and PC connect to. PC has a client thats recieves all data and saves it into csv file. During a run there are only 30 lines in csv and then ERNOMEM happens with some random E:M656 (no idea what that means). Does anybody know how to solve this problem or how to send data every 10ms in other way? Here are codes for access point esp another esp as station and client (on pc): to avoid questions - closing and opening sockets is to achieve data from both esp's in parallel for comparison
import usocket as socket
from machine import I2C, Pin
import mpu6050
from utime import sleep_ms
ssid = 'DRFT'
passwd = 'fiberteam'
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid=ssid, authmode=3, password=passwd, hidden=0)
AP_IP = ap.ifconfig()[0]
print("AP's IP:",AP_IP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((AP_IP, 8888))
s.listen(1)
i2c = I2C(scl=Pin(5), sda=Pin(4))
accelerometer = mpu6050.accel(i2c)
print(accelerometer.get_values())
while True:
if not ap.isconnected():
print("waiting for connection...")
sleep_ms(5000)
else:
while True:
clientsocket, addr = s.accept()
values = accelerometer.get_values()
data_string = str(values['AcX'])+','+str(values['AcY'])+','+str(values['AcZ'])+','
clientsocket.send(bytes(data_string, 'utf-8'))
print(data_string)
clientsocket.close()
sleep_ms(100)
Another ESP:
import network
import usocket as socket
from machine import I2C, Pin
import mpu6050
from utime import sleep_ms
ssid = 'DRFT'
passwd = 'fiberteam'
station = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF) # do not fucin delete dis
ap_if.active(False) # its to turn off access point mode (cuz its a station duh)
station.active(True)
station.connect(ssid, passwd)
station.ifconfig(('192.168.4.69', '255.255.255.0', '192.168.4.1', '8.8.8.8'))
STA_IP = '192.168.4.69'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((STA_IP, 8888))
s.listen(1)
i2c = I2C(scl=Pin(5), sda=Pin(4))
accelerometer = mpu6050.accel(i2c)
print(accelerometer.get_values())
while True:
if not station.isconnected():
print("waiting for connection...")
sleep_ms(5000)
else:
while True:
clientsocket, addr = s.accept()
values = accelerometer.get_values()
data_string = str(values['AcX'])+','+str(values['AcY'])+','+str(values['AcZ'])+','
clientsocket.send(bytes(data_string, 'utf-8'))
print(data_string)
clientsocket.close()
sleep_ms(100)
Client:
import socket
import time
import os
time_now = time.strftime("%Y-%m-%d_%H-%M")
f = open(os.path.join(os.getcwd(), 'DRFT_ride_data'+time_now+'.csv'), 'w+')
f.close()
last_ip_dot = ['1', '69'] # last parts of IP's of boards
curr = 0
last = 0
file = os.path.join(os.getcwd(), 'DRFT_ride_data'+time_now+'.csv')
f = open(file, 'a+')
f.write('fAcX,fAcY,fAcZ,fGyX,fGyY,fGyZ,rAcX,rAcY,rAcZ,rGyX,rGyY,rGyZ,\n')
f.close()
while True:
for dot in last_ip_dot:
curr = int(dot)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect(('192.168.4.'+dot, 8888))
data = s.recv(128)
if len(data) <= 0:
s.close()
continue
if curr == last:
continue
with open(file, 'a+') as f:
f.write(data.decode('utf-8'))
if curr == 69:
f.write('\n')
f.close()
last = curr
s.close()