Hello,
This won't work from my ESP-01S
I know I'm missing something- is the request malformed somehow?
I connect to the wifi- it gets and IP......
This works (test):
r = urequests.get("http://ip-api.com/json/")
print (r.text)
{"status":"success","country":"United States","countryCode":"US","region":"MI","regionName":","city":"and","zip":"","lat":11.11"lon":-81.3734,"timezone":"America/Newwork","is}}
But when try to open this URL (https://python.faith/dax/api4.php?Devices=2Relay) it blows up: (I'm passing data like I do from my pico- that code @ bottom)
r=urequests.get("https://python.faith/dax/api4.php?Devices=2Relay" )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/urequests.py", line 112, in get
File "/lib/urequests.py", line 60, in request
OSError: -40
But the actual page does respond to that URL in a browser:
// 20220813233731
// https://python.faith/dax/api4.php?Devices=2Relay
{
"Devices": "2Relay"
}
Its a very simple php page that looks for a get operation and then reply's back with json.
<?php
$Devices=$_GET['Devices'];
$APIOut = new stdClass();
$APIOut->Devices = $Devices;
$APIOutJSON = json_encode($APIOut);
echo $APIOutJSON;
?>
---------------------------------------------------------------------------------------------------------------
Code that works on my PICO (not ESP-01S): much more complex.... (Its a Get operation even though I named the php file posttest)
pushData="https://python.faith/dax/posttest.php?D ... _Humidity=" + str(dht11hum) + "&Sensor_Temp=" + str(tempfbmp280) + "&DateTime=12/27/2002&Sensor2_name=DHT22&Sensor2_Humidity=" + str(dht22hum) + "&Sensor2_Temp=" + str(dht22temp)
#print(pushData)
r = urequests.get(pushData)
Urequests- What am I doing wrong?
Re: Urequests- What am I doing wrong?
I guess the error came from usocket.wrap_socket because of having less memory for the decryption. I have the same problem with my Server, which offers TSL1.3 and using Elliptic Curve. Furthermore, I can use other hosts with different encryption. Since I'm using the WROVER modules with internal SPIRAM (4 MiB) I never had this issue again.
If you want to keep your Device, then try to change your SSL Settings of your server to offer encryption settings, which the controller could handle.
My testcode:
Result:
I guess if I repeat the same on a WROOM Module without external SPIRAM, I'll get the same error.
If you want to keep your Device, then try to change your SSL Settings of your server to offer encryption settings, which the controller could handle.
My testcode:
Code: Select all
import gc
import micropython
import urequests
URL = micropython.const("https://python.faith/dax/api4.php?Devices=2Relay")
def get():
gc.collect()
print("Mem:", gc.mem_free())
try:
result = urequests.get(URL).json()
except OSError:
print("OSError")
print("Mem:", gc.mem_free())
else:
print("Success")
print("Mem:", gc.mem_free())
gc.collect()
return result
Result:
Code: Select all
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4396
ho 0 tail 12 room 4
load:0x40078000,len:13884
load:0x40080400,len:3340
entry 0x40080618
MicroPython v1.19.1-283-g6f4d424f4-dirty on 2022-08-14; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import gc
=== import micropython
=== import urequests
===
===
=== URL = micropython.const("https://python.faith/dax/api4.php?Devices=2Relay")
===
===
=== def get():
=== gc.collect()
=== print("Mem:", gc.mem_free())
===
=== try:
=== result = urequests.get(URL).json()
=== except OSError:
=== print("OSError")
=== print("Mem:", gc.mem_free())
=== else:
=== print("Success")
=== print("Mem:", gc.mem_free())
===
=== gc.collect()
===
=== return result
===
>>> get()
Mem: 4092144
Success
Mem: 4088496
{'Devices': '2Relay'}
>>> 4092144 - 4088496
3648
>>>
Re: Urequests- What am I doing wrong?
I'm still learning...
Why would it work on a pico but not an esp01?
Why would it work on a pico but not an esp01?
Re: Urequests- What am I doing wrong?
ESP01 is a ESP8266:
SRAM: < 36kB
Flash-Memory: 512kB or 1MB
Pico W (RP2040):
SRAM: 264 KB
Flash-Memory: 2MB
The Raspberry Pi Pico (W) has more SRAM available.
On the ESP8266 is only 36 KiB available.
The ESP32 is the next generation of the ESP8266 with more SRAM. Use your ESP01 for Applications, which don't require TLS (SSL).
SRAM: < 36kB
Flash-Memory: 512kB or 1MB
Pico W (RP2040):
SRAM: 264 KB
Flash-Memory: 2MB
The Raspberry Pi Pico (W) has more SRAM available.
On the ESP8266 is only 36 KiB available.
The ESP32 is the next generation of the ESP8266 with more SRAM. Use your ESP01 for Applications, which don't require TLS (SSL).
Re: Urequests- What am I doing wrong?
You know if one that works with a 2 relay board that you drop in an esp01/S?
Re: Urequests- What am I doing wrong?
Thank you,
Do you think this would be a viable replacement? (Drop in - same form factor).
https://www.aliexpress.com/item/3256803 ... JWWKzfLke9
TTGO T-01C3 ESP32-C3
it says it has 4mb of flash.....
Do you think this would be a viable replacement? (Drop in - same form factor).
https://www.aliexpress.com/item/3256803 ... JWWKzfLke9
TTGO T-01C3 ESP32-C3
it says it has 4mb of flash.....
Re: Urequests- What am I doing wrong?
I had to use a VPN to see the page.
The 400KB SRAM should be enough.
Code: Select all
TTGO T-01C3
Technical details:
MCU : ESP32-C3
CPU : RISC-V 32-bit
Flash : 4Mb
SRAM : 400KB
ROM : 384KB
SRAM in RTC : 8KB
Re: Urequests- What am I doing wrong?
See https://github.com/micropython/micropython/issues/8940 for the ongoing effort to fix the underlying issue here with SSL on ESP32.