Send data from ESP32 to Thonny......how to do ?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
ixbo
Posts: 36
Joined: Wed May 04, 2022 11:12 am
Location: France

Send data from ESP32 to Thonny......how to do ?

Post by ixbo » Sun Jun 05, 2022 11:27 am

Hello....
I have MakePython ESP32 Development Kit with Thonny...

I have made a program witch send data (temperature and humidity) to the web(ThingSpeek) it run well , the BOARD CONNECTED to my PC
The I download my program as main.py into the ESP32 board
I reset the board.....now the program do not word , some files must be not present on my board ?
A part of the program run (temperature and humidity on OLED display ) , but nothing is send to web

Searching to solve the problem
I try a elementary program you can see below named main.py I have downloaded in the ESP32 board
Obviously this program work well and I receive the message 'a very difficult program' when I execute the program with Thonny....but the board alone connected to Pc do not work ?

main.py #my program on ESP32
#****************************************************
print('a very difficult program') #only that !!!!
#****************************************************


Now
*my board always connected to my PC
*Thonny IDE always open
*I reset the board with the reset button

I don't receive the message ? How to do ?

Thanks very much for all suggestions
Best regards

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Send data from ESP32 to Thonny......how to do ?

Post by davef » Sun Jun 05, 2022 6:25 pm

Which shell program are you running on the PC? How have you got the PC setup to see the >>> REPL prompt?

Maybe this helps:
viewtopic.php?t=4944

ixbo
Posts: 36
Joined: Wed May 04, 2022 11:12 am
Location: France

Re: Send data from ESP32 to Thonny......how to do ?

Post by ixbo » Mon Jun 06, 2022 7:40 am

Thank you very much for your answer !

I have no problem with the REPL on THONNY I know how to use it.
(perhaps...)

To recap....
main.py program: print("hello word") downloaded in the board
I reset the board
I would like to see in the REPL window 'hello word' but nothing

With ARDUINO it was possible ( if I remember me ?)

In fact I was searching a most important problem describe earlier. My program who send data to ThingSpeak ,it work very well.....connected to PC but not alone !!! (see it below)
There was two problems

* I did not receive connection information ( print(station.ifconfig()))
* The ESP32 did not work alone



I have found a part of solution I have reset my PC and now my program work well alone, and if I open THONNY then reset my board I receive a message from my board !!!!!!!!! but !!!!!!

(('192.168.1.33', '255.255.255.0', '192.168.1.254', '192.168.1.254'))

if I do the same thing with this extremely difficult program: print("hello word") as main.py of course downloaded in the board I don't receive any message ,doing the same action above !!!!!!!!!!!!!!!!!!

I appreciate very much your answer it allows to advance...
Best regards

Code: Select all

from machine import Pin,I2C
import ssd1306
import usocket as socket
import network
import utime
import dht

# *************INIT************************
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000) 
oled = ssd1306.SSD1306_I2C(128, 64, i2c)

LEDrouge = Pin(21, Pin.OUT)
LEDverte = Pin(22, Pin.OUT)

LEDrouge.value(0)
LEDverte.value(0)
SSID ="Myssid"
PASSWORD = "Mypassword"
APIKEY = "myapikey"
host = "3.223.163.200" # = "api.thingspeak.com"

# *************************************

# *****ACIVATION WIFI BOX*************
def Connection_WIFI():
    station = network.WLAN(network.STA_IF)
    station.active(True)   
    station.connect(SSID, PASSWORD)
    
    while station.isconnected() == False:
        pass
    LEDverte.value(1)	#station connectee
    print(station.ifconfig())
    
# *************DHT11*******************
def Mesure_DHT11():
    d = dht.DHT11(Pin(14))
    d.measure()
    t = d.temperature()
    h = d.humidity()
    return (t,h)
# *************************************

# *************OLED SSD1306************
def Affichage_OLED(t,h):

    oled.fill(0)
    oled.text("Temperture",10,10)
    oled.text(str(t),25,25)
    oled.text("Humidite",10,40)
    oled.text(str(h),25,55)
    oled.show()
    
# *************************************

# *************************************
#         PROGRAMME PRINCIPAL
# *************************************
Connection_WIFI()# dans Boot.py


while True:
    LEDrouge.value(0)
    temperature,humidite = Mesure_DHT11()
    Affichage_OLED(temperature,humidite)

    sock = socket.socket()
    addr = socket.getaddrinfo(host,80)[0][-1]
    sock.connect(addr)
    path = "api_key="+APIKEY+"&field1="+str(temperature)+"&field2="+str(humidite)
    sock.send(bytes("GET /update?%s HTTP/1.0\r\nHost: %s\r\n\r\n" %(path,host),"utf8"))
    sock.close()
   
    LEDrouge.value(1)    #fin de cycle
    utime.sleep(300)
# *************************************

Post Reply