QuestionsCategory: General QuestionESP01 STABILITY USING THINGSPEAK
copo Staff asked 4 years ago

Hello everyone, I’m trying to control a relay from afar using ThingSpeak and the get request function (code linked below). I managed to get it working for some time, but after a while (usually a day or so) the get request stops working for some reason, spitting the following error:
 
ssl_handshake_status: -256
Traceback (most recent call last):
File “main.py”, line 19, in <module>
File “urequests.py”, line 149, in get
File “urequests.py”, line 93, in request
OSError: [Errno 5] EIO
 
— after looking in some forums, I found some people referring to the OSE error as caused by memory issues. Given that the program works and gets hard resetted properly after the selected amount of cycles, I can’t see why it would be caused by that. About the handshake part, all I’ve found is that it might be due to time/dates settings differences between my board and router, which doesn’t really help either…
 

If someone could point me to a forum thread with a similar error solved, I would be elated. Thanks!

btw the board is an esp01 + relay module from aliexpress with a wire soldered to pin 4.

Start your code here

import json,network,sys
import urequests as ureq
from machine import Pin,reset
from time import sleep
cycles = 0

with open(‘wlan_set.json’) as c: # Load network config as a dict
    wlan_set = json.load(c)

sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect(wlan_set[‘ssid’], wlan_set[‘pass’]) # Connect to saved AP
while not sta_if.isconnected():    # Wait until connection is established
    pass
print(‘\n\n Connected to {}’.format(wlan_set[‘ssid’]))

for cycles in range(10):

    ts_data = ureq.get(‘https://api.thingspeak.com/channels/971598/fields/1.json?api_key=CU5423HHCJIR5X91&results=2&#8217😉 #Requests API data

    if not ts_data.status_code == 200:  # Checks status
        print(‘Cant read web’)

    dic_data = ts_data.json()   # Convert data from json to python
    signal = dic_data[‘feeds’][-1][‘field1’]    # Nav to the value we want
    pin2 = Pin(4, Pin.OUT)  # Control GPIO based on value

    print(signal)

    if signal == ‘1’: # Activate the relay for 1 sec
        pin2.on()
        sleep(1)
        pin2.off()
        sleep(15)
        ureq.get(‘https://api.thingspeak.com/update?api_key=295ZUMME6PC3859V&field1=0&#8217😉 # Disables the signal

    sleep(5)

reset()