mayeranalytics / pySX127x

This is a python interface to the Semtech SX127x, HopeRF RFM9x, Microchip RN2483 long range, low power transceiver families.
GNU Affero General Public License v3.0
171 stars 115 forks source link

Not able to transmit or receive data using "Socket_transceiver.py" with another lora connected with Arduino. #25

Closed Akilan89 closed 2 years ago

Akilan89 commented 6 years ago

Hi,

I am new to loRa technology. I am trying to connect create a LoRa gateway using raspberry pi, which collects and sends the data to loRa node(Arduino& LoRa). I have tried your "socket_transceiver.py" program in raspberry pi.. and I am using the below code for arduino..

but i am not able to see the connection happening in between these two LoRa devices.

I am able to send the socket data using a client tool and raspberry pi able to receive that, but i am not able to confirm whether the raspberry pi transmitting the data via lora or not..

I have tried with connecting two raspberry pi nodes but i am not able to see the data transmission.

Please confirm any other settings/configurations needs to be done in raspberry pi side..

Transmitting lora in 434MHz.

Arduino code:

include // include libraries

include

const int csPin = 7; // LoRa radio chip select const int resetPin = 6; // LoRa radio reset const int irqPin = 1; // change for your board; must be a hardware interrupt pin

String outgoing; // outgoing message

byte msgCount = 0; // count of outgoing messages byte localAddress = 0xBB; // address of this device byte destination = 0xFF; // destination to send to long lastSendTime = 0; // last send time int interval = 2000; // interval between sends

void setup() { Serial.begin(9600); // initialize serial while (!Serial);

Serial.println("LoRa Duplex");

// override the default CS, reset, and IRQ pins (optional) LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin

if (!LoRa.begin(915E6)) { // initialize ratio at 915 MHz Serial.println("LoRa init failed. Check your connections."); while (true); // if failed, do nothing }

Serial.println("LoRa init succeeded."); }

void loop() { if (millis() - lastSendTime > interval) { String message = "HeLoRa World!"; // send a message sendMessage(message); Serial.println("Sending " + message); lastSendTime = millis(); // timestamp the message interval = random(2000) + 1000; // 2-3 seconds }

// parse for a packet, and call onReceive with the result: onReceive(LoRa.parsePacket()); }

void sendMessage(String outgoing) { LoRa.beginPacket(); // start packet LoRa.write(destination); // add destination address LoRa.write(localAddress); // add sender address LoRa.write(msgCount); // add message ID LoRa.write(outgoing.length()); // add payload length LoRa.print(outgoing); // add payload LoRa.endPacket(); // finish packet and send it msgCount++; // increment message ID }

void onReceive(int packetSize) { if (packetSize == 0) return; // if there's no packet, return

// read packet header bytes: int recipient = LoRa.read(); // recipient address byte sender = LoRa.read(); // sender address byte incomingMsgId = LoRa.read(); // incoming msg ID byte incomingLength = LoRa.read(); // incoming msg length

String incoming = "";

while (LoRa.available()) { incoming += (char)LoRa.read(); }

if (incomingLength != incoming.length()) { // check length for error Serial.println("error: message length does not match length"); return; // skip rest of function }

// if the recipient isn't this device or broadcast, if (recipient != localAddress && recipient != 0xFF) { Serial.println("This message is not for me."); return; // skip rest of function }

// if message is for this device, or broadcast, print details: Serial.println("Received from: 0x" + String(sender, HEX)); Serial.println("Sent to: 0x" + String(recipient, HEX)); Serial.println("Message ID: " + String(incomingMsgId)); Serial.println("Message length: " + String(incomingLength)); Serial.println("Message: " + incoming); Serial.println("RSSI: " + String(LoRa.packetRssi())); Serial.println("Snr: " + String(LoRa.packetSnr())); Serial.println(); }

mayeranalytics commented 6 years ago

Can you describe your setup in more detail?

One thing I notice is that you configure the Arduino code for 915MHz but you say you use the 433MHz band. Also, LoRa Duplex makes me suspicious. What exactly is you setup?

In any case you should be able to make two Rasp nodes communicate without too much trouble (same software, same module).