Ok…I’m still struggling. The program will send both a help request and an emergency request. Where it gets weird is when you make 5 consecutive activations of combinations of help and emergency requests.
I’ve tried these combinations:
Help, help, help, help, help
Emergency, help, help, help, help
Help, emergency, emergency, emergency, emergency
Emergency, help, Emergency, help, Emergency
Help, emergency, help, emergency, help
After these combinations I get the following error message:
Traceback (most recent call last):
File "main.py", line 61, in <module>
File "urequests.py", line 104, in post
File "urequests.py", line 51, in request
OSError: -2
After the second emergency request I get the following error message:
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x40100000, len 32028, room 16
tail 12
chksum 0x40
ho 0 tail 12 room 4
load 0x3ffe8000, len 1092, room 12
tail 8
chksum 0x17
load 0x3ffe8450, len 3000, room 0
tail 8
chksum 0x56
csum 0x56
Any thoughts and suggestions? Here is the current code:
Code: Select all
import machine
import network
import time
import urequests
from machine import Timer
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('xxxxxxxxxxxx', 'xxxxxxxxxx')
button = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP)
redled = machine.Pin(5, machine.Pin.OUT)
yelled = machine.Pin(12, machine.Pin.OUT)
grnled = machine.Pin(4, machine.Pin.OUT)
url_01 = 'http://api.pushingbox.com/pushingbox?devid=xxxxxxxxxxxxxxx'
url_02 = 'http://api.pushingbox.com/pushingbox?devid=xxxxxxxxxxxxxx'
buttonCounter = 0
helpFlag = False
def helpRequest():
if buttonCounter == 1:
global helpFlag
helpFlag = True
elif buttonCounter == 2:
global helpFlag
helpFlag = True
def emergencyRequest():
from machine import Timer
print('Emergency')
resp = urequests.post(url_02)
redled(1)
tim2 = Timer(1)
tim2.init(period=10000, mode=Timer.ONE_SHOT, callback=lambda t:redled(0))
def buttonReset(self):
helpRequest()
global buttonCounter
buttonCounter = 0
print('reset')
print(buttonCounter)
while True:
first = button.value()
time.sleep(0.05)
second = button.value()
if first and not second:
print('Button pressed!')
buttonCounter = buttonCounter + 1
print(buttonCounter)
tim3 = Timer(2)
tim3.init(period=2000, mode=Timer.ONE_SHOT, callback=buttonReset)
if buttonCounter >= 3:
emergencyRequest()
buttonCounter = 0
if helpFlag == True:
resp = urequests.post(url_01)
helpFlag = False
print('Help 2')
yelled(1)
tim = Timer(-1)
tim.init(period=10000, mode=Timer.ONE_SHOT, callback=lambda t:yelled(0))
if wlan.isconnected() == True:
grnled(1)
elif wlan.isconnected() == False:
grnled(0)