Either network or requests module reboot the board

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
yeyeto2788
Posts: 28
Joined: Wed Mar 30, 2016 4:09 pm

Either network or requests module reboot the board

Post by yeyeto2788 » Wed Oct 03, 2018 12:17 pm

Hello guys,

I have encounter a problem trying to make a script that just checks the price for bitcoins the code is the following:

Code: Select all

from console import Display
import urequests
import json
import time
#import gc

oled = Display()


def ConnectWifi(SSID, pwd):
    """
    Function to connect to WIFI.

    Args:
        SSID: String with the name of the WIFI connection.
        pwd: String with the WiFi password.

    Returns: True if it's connected to wifi

    """
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        oled.clear(0, 1)
        oled.print_wrapped('Connecting to network...')
        time.sleep(1)
        sta_if.active(True)
        sta_if.connect(SSID, pwd)
        while not sta_if.isconnected():
            pass

def GetTime():
    """
    Get local time from the internet.

    Returns: Nothing

    """
    import ntptime
    ntptime.settime()
    ts = time.localtime()
    year = ts[0]
    Month = ts[1]
    day = ts[2]
    hour = ts[3]
    mins = ts[4]
    dayYear = ts[7]
    ActualTime = "%s/%s/%s %s:%s" % (str(day), str(Month), str(year), str(hour), str(mins))
    return ActualTime




SSID = "SSIDName"
pwd = "SSIDPassword"

ConnectWifi(SSID, pwd)
while True:
    #print("Free out: " + str(gc.mem_free()))
    r = urequests.get("https://api.coindesk.com/v1/bpi/currentprice/EUR.json")
    Data = r.json()
    USD = Data["bpi"]["USD"]["rate_float"]
    EUR = Data["bpi"]["EUR"]["rate_float"]
    Date = Data["time"]["updated"]
    oled.clear(0, 1)
    oled.print_on_line("Price from %s" % Date.split(",")[0], 0)
    oled.print_on_line(str(Date.split(",")[1].lstrip()))
    oled.print_on_line("USD: %s" % str(USD), 2)
    oled.print_on_line("EUR: %s" % str(EUR), 3)
    time.sleep(10)
The problems comes when executing the code:

Code: Select all

>>> import bitcoin_price

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 31108, room 16
tail 4
chksum 0x28
load 0x3ffe8000, len 1100, room 4
tail 8
chksum 0x4e
load 0x3ffe8450, len 3268, room 0
tail 4
chksum 0x09
csum 0x09
▒
$▒▒|▒▒2rrnc▒▒▒
l▒
"▒$
B▒ܜ▒▒
#
▒#l`ll▒▒|▒▒so"▒▒▒ll▒l
#▒▒c䌜▒▒b▒
c▒
▒l{$▒l▒▒|▒▒{ob▒▒▒l▒▒b▒
#▒ܜ▒▒b▒$cl▒▒▒N▒{▒▒o|▒
$
$ld`b▒▒|r▒l▒n▒▒n▒
d`▒▒{▒l▒$2▒
l ▒▒{▒l▒$
l ▒▒{▒p▒
▒▒▒
$l {l▒▒▒c▒▒▒c
▒▒#|lc▒▒b|▒▒▒▒
dlc▒▒o▒2Nn▒▒$n▒▒▒▒$▒ld▒▒▒
$`▒o▒▒▒▒cBl$섏▒
c▒▒▒#l▒#r$rdr▒o▒▒▒
▒2c{#▒▒"▒b▒▒cl▒p▒▒s"
▒"▒▒n▒߀▒c{#▒▒"▒b▒▒cd▒
B▒▒{bl ▒l▒▒▒▒▒rNc▒▒▒▒▒▒
▒c▒
b䌜▒▒|▒▒
#l$cl▒▒lo▒l ▒▒lo▒p{l▒$ܞ|▒2▒▒rn#▒▒▒▒▒▒r▒#▒▒#5 ets_task(40100130, 3, 3fff83ec, 4)
OSError: [Errno 2] ENOENT

MicroPython v1.9.4-8-ga9a3caad0 on 2018-05-11; ESP module with ESP8266
Type "help()" for more information.
>>>
The board automatically reboot and it seems to be coming either from the requests module or the network one, the weird part is that from the REPL the error is not reproduced:

Code: Select all

>>> import network
>>> import urequests
>>> sta_if = network.WLAN(network.STA_IF)
>>> sta_if.isconnected()
True
>>> r = urequests.get("https://api.coindesk.com/v1/bpi/currentprice/EUR.json")
>>> Data = r.json()
>>> Data
{'time': {'updated': 'Oct 3, 2018 12:15:00 UTC', 'updatedISO': '2018-10-03T12:15:00+00:00', 'updateduk': 'Oct 3, 2018 at 13:15 BST'}, 'disclaimer': 'This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org', 'bpi': {'EUR': {'code': 'EUR', 'description': 'Euro', 'rate_float': 5593.94, 'rate': '5,593.9390'}, 'USD': {'code': 'USD', 'description': 'United States Dollar', 'rate_float': 6459.77, 'rate': '6,459.7675'}}}
>>>
Anyone that could help me out here?

Regards.

P.D: If you want more info about the console module head over https://github.com/yeyeto2788/MicroPyth ... iptConsole

Post Reply