Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Upload issue due to 2-line code

    Scheduled Pinned Locked Moved Pymakr
    11 Posts 3 Posters 101 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • robert-hhR Offline
      robert-hh @frederik Leys
      last edited by

      @frederik-Leys Pull P12 up (connect to 3.3V) and push reset. Then, boot.py and main.py will not be executed.

      1 Reply Last reply Reply Quote 1
      • E Offline
        Elias Tapia
        last edited by

        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?

        robert-hhR 1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @Elias Tapia
          last edited by

          @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.

          E 2 Replies Last reply Reply Quote 0
          • E Offline
            Elias Tapia @robert-hh
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • E Offline
              Elias Tapia @robert-hh
              last edited by robert-hh

              @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?

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @Elias Tapia
                last edited by

                @Elias-Tapia I uinderstand that you have issues to update the Python code. Which tool do you use to update the Python code?

                E 1 Reply Last reply Reply Quote 0
                • E Offline
                  Elias Tapia @robert-hh
                  last edited by

                  @robert-hh I am using atom, with the pymakr plugin

                  robert-hhR 1 Reply Last reply Reply Quote 0
                  • robert-hhR Offline
                    robert-hh @Elias Tapia
                    last edited by

                    @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.

                    E 1 Reply Last reply Reply Quote 0
                    • E Offline
                      Elias Tapia @robert-hh
                      last edited by

                      @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

                      robert-hhR 1 Reply Last reply Reply Quote 0
                      • robert-hhR Offline
                        robert-hh @Elias Tapia
                        last edited by

                        @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.

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • 1 / 1
                        • First post
                          Last post

                        Pycom on Twitter

                        Pycom