Jul-31-2019, 05:05 PM
Hello:
I am new to this forum. I am having an issue trying to figure out how to do something seemingly simple, but spinning the wheels. I have searched as many resources as I can, but do not seem to able to find an example. Even books I have bought do not cover how to do this, they're really focused on running the device in 'station mode'.
The device I am using is the ESP32, which I want to act as a soft access data "server". Here's the objective:
-boot the ESP32 in WAP (soft access) mode
-controller begin processing data from the ADC
-wait for connection
-when connection is initiated, begin streaming data at rate 'x". For this I will use a controlled loop or a thread.
-the data will be integers in the range of int16's
At the other side (client) the laptop (for now) will launch a console application to connect to the soft point and receive data and display it in the console.
That's it! My weakness is with using sockets...what I have so far is below. Seems it should be something that is common application, but after many searches I cannot find a basic example.
Can someone provide the missing pieces, or let me know of a resource that I could read to understand how to do this?
Thanks!
Gary
I am new to this forum. I am having an issue trying to figure out how to do something seemingly simple, but spinning the wheels. I have searched as many resources as I can, but do not seem to able to find an example. Even books I have bought do not cover how to do this, they're really focused on running the device in 'station mode'.
The device I am using is the ESP32, which I want to act as a soft access data "server". Here's the objective:
-boot the ESP32 in WAP (soft access) mode
-controller begin processing data from the ADC
-wait for connection
-when connection is initiated, begin streaming data at rate 'x". For this I will use a controlled loop or a thread.
-the data will be integers in the range of int16's
At the other side (client) the laptop (for now) will launch a console application to connect to the soft point and receive data and display it in the console.
That's it! My weakness is with using sockets...what I have so far is below. Seems it should be something that is common application, but after many searches I cannot find a basic example.

Can someone provide the missing pieces, or let me know of a resource that I could read to understand how to do this?
Thanks!
Gary
import socket import network ap = network.WLAN(network.AP_IF) ap.active(True) ap.config(essid='CPTS-A3D', authmode=network.AUTH_WPA_WPA2_PSK, password='password') ap.ifconfig(('192.168.4.1', '255.255.255.0', '192.168.4.1', '192.168.4.1')) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #pick a port...should this call be: s.bind(('0,0,0,0', 10000)) ?? s.bind(('', 10000)) s.listen(5) while True: conn, addr = s.accept() #display activity print('Got a connection from %s' % str(addr)) #should this be less bytes for what I need to do? request = conn.recv(1024) # THIS IS WHERE I AM TRYING TO FIGURE OUT #HOW TO SEND DATA #the next line is part of the 'web server/html' code I found #not sure if it will be part of the solution conn.sendall(response) conn.close()