Upload issue due to 2-line code
-
I can't upload code to my Pycom Fipy anymore because this is the code that is running:
import pycom import machine import time from network import LTE print("ik ga slapen") machine.deepsleep(40*1000)
when i try to upload code i get this reaction
Uploading project (main folder)... Safe booting device... (see settings for more info) Safe boot failed, uploading anyway. Uploading to /flash... Upload failed.: timeout Please reboot your device manually.
but if i reset manually the device goes immediately in deepsleep as i coded...
so how can i upload other code to my Pycom?
kind regards,
-
@Elias-Tapia Assuming you have the LOPY4 attached to some kind of USB/Serial interface, like an expansion board, the Updater should always work. You can try to force the ESP32 into update mode by pulling P2 to GND an pushing Reset. You msut as well verify that you use the proper Serial port on your PC.
-
@robert-hh thanks a lot, it works on terminal,i'll implement gc.collect() then..
One more thing I have a LOPY4 unable to be udpated by pycom firmware udpater but this error came out: The upgrade failed due to the following error:
Failed to connect to Espressif device: No serial data received.For
troubleshooting steps visit: https://docs.espressif.com/projects/
esptool/en/latest/troubleshooting.html, but the link gives the error 404 page not found
-
@Elias-Tapia Using Ctrl-C from a serial terminal you should be able to interrupt your code and get a REPL prompt, unless your code disables keyboard interrupt. For that situation pulling up P12 and pushing reset helps. It skips execution of boot.py and main.py and gets you to a REPL prompt. Then, you can change or replace main.py & boot.py. All these low level operations are better done with a simple serial terminal and NOT IDE's like pymakr or Thonny.
It is good practice to put your main application not into main.py, but in a file with e.g. the name my_app.py, and have main.py just be something like:import time time.sleep(3) import my_app
That gives you a time slot of 3 seconds to interrupt the start process.
I cannot tell you a lot about the disconnection problem. Things that happen only after days are hard to trace. Maybe it's a memory fragmentation problem. Then it might help to add
gc.collect()
to the main loop of your code.
Note:
Using P12 pull-up does NOT stop the hidden _boot.py and _main.py.
-
@robert-hh I am using atom, with the pymakr plugin
-
@Elias-Tapia I uinderstand that you have issues to update the Python code. Which tool do you use to update the Python code?
-
@robert-hh would this work with my pysense? I am using a pysense and a lopy4, the thing is that I have two issues when I upgrade my firmware: with the pycom firmware update v1.17.0.b4-development, I am able to upload my code this works, I'm receiving the data on chirpstack and influxdb. Now I want to update the new code but the first thing that appears is OSError: [Errno 17] EEXIST pycom then: Uploading project (main folder)...
The safe booting device... (see settings for more info)
Safe boot failed, uploading anyway.
Uploading to /flash...
Upload failed.: timeout Please reboot your device manually.
So I have to upload again the firmware with the tool. That is my first issue.
The second is that my node is only able to send over a day or two then it disconnects from my chirpstack and unless I disconnect the device and reconect tothe source again it would not send the data, this is the code of the pysense:code_text
#!/usr/bin/env python # # Copyright (c) 2019, Pycom Limited. # # This software is licensed under the GNU GPL version 3 or any # later version, with permitted additional terms. For more information # see the Pycom Licence v1.0 document supplied with this file, or # available at https://www.pycom.io/opensource/licensing # """ OTAA Node example as per LoRaWAN AS923 regional specification - compatible with the LoPy Nano Gateway and all other LoraWAN gateways - tested works with a LoRaServer, shall works on TTN servers """ from network import LoRa import socket import binascii import struct import time import pycom from CayenneLPP import CayenneLPP from pysense import Pysense from LIS2HH12 import LIS2HH12 from SI7006A20 import SI7006A20 from LTR329ALS01 import LTR329ALS01 from MPL3115A2 import MPL3115A2, ALTITUDE, PRESSURE py = Pysense() si = SI7006A20(py) lt = LTR329ALS01(py) li = LIS2HH12(py) # Disable heartbeat LED pycom.heartbeat(False) LORA_CHANNEL = 1 LORA_NODE_DR = 4 ''' utility function to setup the lora channels ''' def prepare_channels(lora, channel, data_rate): AS923_FREQUENCIES = [ { "chan": 1, "fq": "923200000" }, #{ "chan": 2, "fq": "923400000" }, #{ "chan": 3, "fq": "922200000" }, #{ "chan": 4, "fq": "922400000" }, #{ "chan": 5, "fq": "922600000" }, #{ "chan": 6, "fq": "922800000" }, #{ "chan": 7, "fq": "923000000" }, #{ "chan": 8, "fq": "922000000" }, ] if not channel in range(0, 9): raise RuntimeError("channels should be in 1-8 for AS923") if channel == 0: import uos channel = (struct.unpack('B',uos.urandom(1))[0] % 7) + 1 for i in range(0, 8): lora.remove_channel(i) upstream = (item for item in AS923_FREQUENCIES if item["chan"] == channel).__next__() # set default channels frequency lora.add_channel(int(upstream.get('chan')), frequency=int(upstream.get('fq')), dr_min=0, dr_max=data_rate) return lora ''' call back for handling RX packets ''' def lora_cb(lora): events = lora.events() if events & LoRa.RX_PACKET_EVENT: if lora_socket is not None: frame, port = lora_socket.recvfrom(512) # longuest frame is +-220 print(port, frame) if events & LoRa.TX_PACKET_EVENT: print("tx_time_on_air: {} ms @dr {}", lora.stats().tx_time_on_air, lora.stats().sftx) ''' Main operations: this is sample code for LoRaWAN on AS923 ''' lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AS923, device_class=LoRa.CLASS_A, adr=True) # create an OTA authentication params dev_eui = binascii.unhexlify('******') app_eui = binascii.unhexlify('********') #nwk_key = binascii.unhexlify('******') app_key = binascii.unhexlify('********') # join a network using OTAA lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0, dr=2) # AS923 always joins at DR2 prepare_channels(lora, LORA_CHANNEL, LORA_NODE_DR) # wait until the module has joined the network print('Over the air network activation ... ', end='') while not lora.has_joined(): time.sleep(2.5) print('.', end='') print('OTAA joined') # create a LoRa socket lora_socket = socket.socket(socket.AF_LORA, socket.SOCK_RAW) # set the LoRaWAN data rate lora_socket.setsockopt(socket.SOL_LORA, socket.SO_DR, LORA_NODE_DR) # msg are confirmed at the FMS level lora_socket.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, 0) # make the socket non blocking y default lora_socket.setblocking(False) lora.callback(trigger=( LoRa.RX_PACKET_EVENT | LoRa.TX_PACKET_EVENT | LoRa.TX_FAILED_EVENT ), handler=lora_cb) time.sleep(4) # this timer is important and caused me some trouble ... for i in range(0, 100000000): #pkt = struct.pack('>H', i) #print('Sending:', pkt) #lora_socket.send(pkt) #time.sleep(300) pycom.rgbled(0x000014) lpp = CayenneLPP() print('\n\n** Humidity and Temperature Sensor (SI7006A20)') print('Humidity', si.humidity()) print('Temperature', si.temperature()) lpp.add_relative_humidity(1, si.humidity()) lpp.add_temperature(1, si.temperature()) mpPress = MPL3115A2(py,mode=PRESSURE) print('\n\n** Barometric Pressure Sensor with Altimeter (MPL3115A2)') print('Pressure (hPa)', mpPress.pressure()/100) lpp.add_barometric_pressure(1, mpPress.pressure()/100) ''' print('\n\n**LoRa stats') SNR=lora.stats().snr RSSI=lora.stats().rssi print("SNR: {}u @RSSI: {}".format(SNR, RSSI)) lpp.add_snr(1, SNR) lpp.add_rssi(1, RSSI) ''' encoded_payload = lpp.get_buffer() print('Sending data (uplink)...') lora_socket.send(bytes(encoded_payload)) #lora_socket.setblocking(False) data = lora_socket.recv(64) #Payload payload_size = len(encoded_payload) print("Payload size:", payload_size, "bytes") #Data print('Received data (downlink)', data) pycom.rgbled(0x001400) time.sleep(300)
Any ideas?
-
This post is deleted!
-
@Elias-Tapia See the previous post:
Pull P12 up (connect to 3.3V) and push reset. Then, boot.py and main.py will not be executed.
-
I have the same problem, but I'm not using deep sleep, I only am able to upload new code if I upload the firmware again, any ideas?
-
@frederik-Leys Pull P12 up (connect to 3.3V) and push reset. Then, boot.py and main.py will not be executed.