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

    Adding information to _make_node_packet(...)

    Scheduled Pinned Locked Moved Support & Troubleshooting
    lorawanlorawan nano gwttn gatewayttn lopybattery
    1 Posts 1 Posters 188 Views 1 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.
    • C Offline
      crispycrafter
      last edited by

      I am currently setting up a lorawan nanogateway ( in preparation for my pygate) .
      The nanogateway is implemented on a Lopy4, using the default nanogateway.py code supplied by pycom.

      My use case does however require that I use solar to power the gateway and nodes. Currently the setup is working smoothly, however I have no way to inspect and send the gateway voltage via Lora > TTN > DB

      I have tried modifying the nanogateway code as follows:

      from machine import ADC
      ...
      def __init__(self):
           ...
            self.voltage_pin = ADC().channel(pin='P18', attn=ADC.ATTN_11DB)
           ...
      
      ...
      
      def get_battery_voltage(self):
             # Get pin 18 voltage using voltage devider
              R1 = 47*1000    
              R2 = 100*1000  
              battery = self.voltage_pin.voltage()*(R1 + R2)/R2
              return battery/1000
      ...
      
      def _make_node_packet(self, rx_data, rx_time, tmst, sf, bw, rssi, snr):
              bat = self.get_battery_voltage() 
              RX_PK["rxpk"][0]["time"] = "%d-%02d-%02dT%02d:%02d:%02d.%dZ" % (rx_time[0], rx_time[1], rx_time[2], rx_time[3], rx_time[4], rx_time[5], rx_time[6])
              RX_PK["rxpk"][0]["tmst"] = tmst
              RX_PK["rxpk"][0]["freq"] = self._freq_to_float(self.frequency)
              RX_PK["rxpk"][0]["datr"] = self._sf_bw_to_dr(sf, bw)
              RX_PK["rxpk"][0]["rssi"] = rssi
              RX_PK["rxpk"][0]["lsnr"] = snr
              RX_PK["rxpk"][0]["data"] = ubinascii.b2a_base64(rx_data)[:-1]
              RX_PK["rxpk"][0]["size"] = len(rx_data)
              RX_PK["rxpk"][0]["gw_voltage"] = bat
              return ujson.dumps(RX_PK)
      

      Conceptually this works well as I receive gw_voltage in my terminal over pybytes:
      ebcec001-7140-4412-a78a-071f8dcedb59-image.png
      (Battery not connected value expected to be <0V)

      However gw_voltage is not present on TTN.

      How can I go about fixing this? Or is there an alternative approach?
      Thanks!
      Re: lorawan nanogateway pytrack gps

      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