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 “”, line 19, in <module>
File “”, line 149, in get
File “”, 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.connect(wlan_set[‘ssid’], wlan_set[‘pass’]) # Connect to saved AP
while not sta_if.isconnected():    # Wait until connection is established
print(‘\n\n Connected to {}’.format(wlan_set[‘ssid’]))

for cycles in range(10):

    ts_data = ureq.get(‘😉 #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


    if signal == ‘1’: # Activate the relay for 1 sec
        ureq.get(‘😉 # Disables the signal