0

I have a problem on the counter in TTN. this problem happened after I added machine.deepsleep function in my LoPy4. I have used the nvram_save () and nvram_restore () functions, but the counter in TTN still not increment. this screenCapture :

enter image description here

So, what's the problem in this case ?

this my code :

enter code here

import ads1x15 as extADC
import gc
import pycom
import socket
from network import LoRa
from uModBus.serial import Serial
from network import LoRa
import machine
import ubinascii
import utime
from machine import RTC, I2C
from machine import Pin


pycom.heartbeat(False)
rtc = RTC()
i2c = I2C(0, I2C.MASTER, pins=('P3', 'P4'), baudrate=100000)
adc = extADC.ADS1115(i2c, gain=1)
pinTrig = Pin('P23', mode=Pin.OUT)

# LoRa Socket Connection with two condition

if machine.reset_cause() == machine.DEEPSLEEP_RESET:
      pinTrig.value(1)  # enable High (12v)
      print("WOKE UP FROM DEEPSLEEP 3 MINUTES !")
      utime.sleep(1)
      lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AS923)

      lora.nvram_restore() # Nvram restore function

      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
      s.setblocking(False)
      s.bind(1)
else:
      pinTrig.value(1)
      utime.sleep(1)
      print("I'M PowerOn by Humans or Hard reset !")
      lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AS923)

      lora.nvram_restore() # Nvram restore function

      app_eui = ubinascii.unhexlify('********************')
      app_key = ubinascii.unhexlify('-----------------------------')
      lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
      while not lora.has_joined():
            utime.sleep(2.5)
            print('Not yet joined...')

      print('Joined')
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
      s.setblocking(True)
      s.bind(1)


      ### Begin sensor reading and sending function ##################

      def read_data_Sensor () :


      ### End sensor reading and sending function ####################


      try:
          read_data_Sensor()

          lora.nvram_save() 

          utime.sleep(1)
          pinTrig.value(0)
          print("DeepSleep Mode")
          utime.sleep(1)

          machine.deepsleep(180000)
      except OSError:
          print("Terjadi Error - Restart")
          s.send(b"\xff\xff")
          utime.sleep(1)
          machine.reset()
Tarick Welling
  • 3,119
  • 3
  • 19
  • 44
Ibnu
  • 11
  • 3

1 Answers1

0

My understanding of the nvmram_save/restore methods is that they restore the full state of the lora stack, including the 'joined/not joined' status. If you explicitly do the join() every time, then this both wastes energy/time in the join exchange, and this process will always reset the counters back to 0.

I think your code should test lora.has_joined() after the nvram_restore(), and only do the join procedure if this returns False.

btw I have also experienced issues with pycom and nvmram_save/restore with TTN v3.

cigien
  • 57,834
  • 11
  • 73
  • 112
Brian
  • 56
  • 2