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

    LoRa Communication Between FiPy and Adafruit Feather 32u4 Running RadioHead Library

    Scheduled Pinned Locked Moved Discussion
    radioheadfeather 32u4
    4 Posts 3 Posters 43 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.
    • E Offline
      Edward
      last edited by

      Hi,

      I'm trying to receive the packets sent out from a Feather 32u4 using the RadioHead library on the FiPy; however, no matter what settings I try to adjust, I cannot seem to receive any of the packets sent by the feather. The feather uses a RFM95W. What I am trying to do is similar to this forum post from earlier (https://forum.pycom.io/topic/693/lopy-communication-with-rfm95-modules), where I am just trying to receive and read out the packets.

      Currently, I am stuck where I cannot receive the packets on the FiPy in the first place, and would greatly appreciate any help I could get.

      Here is the code on the FiPy:

      import struct
      import socket
      from network import LoRa
      import time
      import gc
      
      LORA_MSG_FORMAT = "LLBBBBlB" 
      
      
      class incoming_message:
          def __init__(self, data):
             self.control, self.deviceID, self.Seq, self.indicator1,  self.indicator2,  self.stype,  self.svalue,  self.check = struct.unpack(LORA_MSG_FORMAT, data)
      #self.control is something added from RFM95. Just discard it. Your message starts from the 5th byte
      
      class server:
          def __init__(self):
              cfg_mode = LoRa.LORA
              cfg_freq = 915000000
              cfg_bandwidth=LoRa.BW_125KHZ        # LoRa.BW_125KHZ or LoRa.BW_250KHZ
              cfg_sf = 7                          # Accepts values between 6 and 12.
                                                  #  6 =   64  Chips/Symbol
                                                  #  7 =  128  Chips/Symbol
                                                  #  8 =  256  Chips/Symbol
                                                  #  9 =  512  Chips/Symbol
                                                  # 10 = 1024  Chips/Symbol
                                                  # 11 = 2048  Chips/Symbol
                                                  # 12 = 4096  Chips/Symbol
                                                  
              cfg_preamble=8                      #configures the number of pre-amble symbols. The default value is 8
              cfg_coding_rate=LoRa.CODING_4_5     #LoRa.CODING_4_5, LoRa.CODING_4_6, LoRa.CODING_4_7 or LoRa.CODING_4_8
              cfg_power_mode=LoRa.ALWAYS_ON       #LoRa.ALWAYS_ON, LoRa.TX_ONLY or LoRa.SLEEP
              
              self.lora = LoRa(mode=cfg_mode,
                frequency=cfg_freq,
                tx_power=14,
                bandwidth=cfg_bandwidth,
                sf=cfg_sf,
                preamble=cfg_preamble,
                coding_rate=cfg_coding_rate,
                power_mode=cfg_power_mode,
                tx_iq=False,
                rx_iq=False, 
                public=False)
              
              self.lora.init(mode=cfg_mode,
                frequency=cfg_freq,
                tx_power=14,
                bandwidth=cfg_bandwidth,
                sf=cfg_sf,
                preamble=cfg_preamble,
                coding_rate=cfg_coding_rate,
                power_mode=cfg_power_mode,
                tx_iq=False,
                rx_iq=False, 
                public=False)
              self.lora_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
              self.lora_sock.setblocking(False)
          def update(self):
              raw_data = self.lora_sock.recv(61)
              
              if raw_data:
                  try:
                      msg = incoming_message(raw_data)
                      if msg.deviceID % msg.Seq == msg.check:
                          print("msg received. devid:", msg.deviceID,  " seq:", msg.Seq)
                      else:
                          print("msg check failed")    
                  except:
                      print("msg failed to parse")
              else:
                  pass
      
      def test_server():
          srv = server()
          while True:
              srv.update()
              
              
      test_server()
      

      And here is the code I am running on the Feather:

      #include <SPI.h>
      #include <RH_RF95.h>
      
      #define FREQUENCY  915.0
      
      struct tpayload {
         uint32_t deviceid;   //4
         byte seq;            //1
         byte indicator1;     //1
         byte indicator2;     //1
         byte stype;          //1
         long svalue;         //4
         byte check;          //1
      };
      
      tpayload payload;
      RH_RF95 rf95(8,7);    // Chip Select=8, INT Pin = 7
      
      void setup() {
        Serial.begin(57600);
        while(!Serial);
        if (!rf95.init()) {
           Serial.println("init failed");
        }
        if (!rf95.setFrequency(FREQUENCY)) { 
          Serial.print("init freq failed"); 
        }
      
        payload.seq = 0;
        payload.deviceid = 8512;
        payload.indicator1 = 1;
        payload.indicator1 = 2;
        payload.stype = 2;
        payload.svalue = -10;
      }
      
      void loop() {
        payload.seq++;
        if (payload.seq == 0) payload.seq++;  // to avoid division by zero at the next line
        payload.check = payload.deviceid % payload.seq;  // you need this to discard corrupted messages
        uint16_t now = micros();
        rf95.send( (const void*)&payload, sizeof(payload));
        delay(5000);
      }
      

      In the RadioHead Library I have edited in the matching modem config settings, so I am not quite sure what I am still missing. Again, I would greatly appreciate any help I could get!

      A 1 Reply Last reply Reply Quote 0
      • A Offline
        andreas @Edward
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • E Offline
          Edward
          last edited by

          I should probably clarify what I am trying to do a bit better:

          I am trying to use the code that constantinos and Clemens posted earlier, just to try to get a version that will receive packets from the feather in the first place. I looked through the forum for other posts and have tried tinkering with the different settings to no avail.

          Forgive me for any mistakes I am making, as I am new to this and trying to figure it out! Again, I would greatly appreciate any help I can get!

          1 Reply Last reply Reply Quote 0
          • N Offline
            nowakowski912 Banned
            last edited by

            This post is deleted!
            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