• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

raspberry LoRa point to point communication

Q&A Forum › Category: Raspberry Pi › raspberry LoRa point to point communication
0 Vote Up Vote Down
delmarcodiego asked 4 years ago

Hi guys,

like in the title i ask you the easiest way to do that.

I have 2 Heltec Wifi lora esp32 with oled and sx1278 and they work fine, i have tested with success the WiFi_LoRa_32FactoryTest.ino, I would like with a raspberry to decide which text to send by heltec card with LoRa, and read it with another raspberry.

Raspberry(A)—>Heltec(A)—> ……………… by LoRa …………………. —> Heltec(B)—>Raspberry(B)

and viceversa

Raspberry(B)—>Heltec(B)—> ……………… by LoRa ………………… —> Heltec(A)—>Raspberry(A)

Thanks in advance for any suggestions, I enclose the code that runs on the heltec board, in raspberry i use python

but also java.

WiFi_LoRa_32FactoryTest.ino (by heltec):

#include "Arduino.h"
#include "heltec.h"
#include "WiFi.h"
#include "images.h"

String rssi = "RSSI --";
String packSize = "--";
String packet;

unsigned int counter = 0;

bool receiveflag = false; // software flag for LoRa receiver, received data makes it true.

long lastSendTime = 0; // last send time
int interval = 1000; // interval between sends

void logo(){
Heltec.display -> clear();
Heltec.display -> drawXbm(0,5,logo_width,logo_height,(const unsigned char *)logo_bits);
Heltec.display -> display();
}

void WIFISetUp(void)
{
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.disconnect(true);
delay(1000);
WiFi.mode(WIFI_STA);
WiFi.setAutoConnect(true);
WiFi.begin("Your SSID","Your Password");
delay(100);

byte count = 0;
while(WiFi.status() != WL_CONNECTED && count < 10)
{
count ++;
delay(500);
Heltec.display -> drawString(0, 0, "Connecting...");
Heltec.display -> display();
}

Heltec.display -> clear();
if(WiFi.status() == WL_CONNECTED)
{
Heltec.display -> drawString(0, 0, "Connecting...OK.");
Heltec.display -> display();
// delay(500);
}
else
{
Heltec.display -> clear();
Heltec.display -> drawString(0, 0, "Connecting...Failed");
Heltec.display -> display();
//w hile(1);
}
Heltec.display -> drawString(0, 10, "WIFI Setup done");
Heltec.display -> display();
delay(500);
}

void WIFIScan(unsigned int value)
{
unsigned int i;
for(i=0;i<value;i++)
{
Heltec.display -> drawString(0, 20, "Scan start...");
Heltec.display -> display();

int n = WiFi.scanNetworks();
Heltec.display -> drawString(0, 30, "Scan done");
Heltec.display -> display();
delay(500);
Heltec.display -> clear();

if (n == 0)
{
Heltec.display -> clear();
Heltec.display -> drawString(0, 0, "no network found");
Heltec.display -> display();
while(1);
}
else
{
Heltec.display -> drawString(0, 0, (String)n);
Heltec.display -> drawString(14, 0, "networks found:");
Heltec.display -> display();
delay(500);

for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Heltec.display -> drawString(0, (i+1)*9,(String)(i + 1));
Heltec.display -> drawString(6, (i+1)*9, ":");
Heltec.display -> drawString(12,(i+1)*9, (String)(WiFi.SSID(i)));
Heltec.display -> drawString(90,(i+1)*9, " (");
Heltec.display -> drawString(98,(i+1)*9, (String)(WiFi.RSSI(i)));
Heltec.display -> drawString(114,(i+1)*9, ")");
// display.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
delay(10);
}
}

Heltec.display -> display();
delay(800);
Heltec.display -> clear();
}
}

void setup()
{
Heltec.begin(true /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, 868E6 /*LoRa RF working band*/);

logo();
delay(300);
Heltec.display -> clear();

WIFISetUp();
WIFIScan(1);

LoRa.onReceive(onReceive);
LoRa.receive();
}

void loop()
{
if(millis() - lastSendTime > interval)//waiting LoRa interrupt
{
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter++);
LoRa.endPacket();

LoRa.receive();

digitalWrite(LED,HIGH);
Heltec.display -> drawString(0, 50, "Packet " + (String)(counter-1) + " sent done");
Heltec.display -> display();

interval = random(1000) + 1000; //1~2 seconds
lastSendTime = millis();

Heltec.display -> clear();
}
if(receiveflag)
{
Heltec.display -> drawString(0, 0, "Received Size" + packSize + " packages:");
Heltec.display -> drawString(0, 10, packet);
Heltec.display -> drawString(0, 20, "With " + rssi);
Heltec.display -> display();

digitalWrite(25,LOW);

receiveflag = false;
}
}

void onReceive(int packetSize)//LoRa receiver interrupt service
{
//if (packetSize == 0) return;

packet = "";
packSize = String(packetSize,DEC);

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

Serial.println(packet);
rssi = "RSSI: " + String(LoRa.packetRssi(), DEC);

receiveflag = true;
}
Question Tags: Hi guys
2 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
If I understood well, you would like to send commands to your heltec board using a raspberry pi, and then from an heltec board to the raspberry pi. Is that correct?
I’ve never done anything like that. You can send commands via MQTT between the ESP32 and the Raspberry Pi board, but I don’t know if it will work well using LoRa at the same time. I guess you’ll have to try it to figure it out.
I’m sorry that I can’t help much in this subject.
If you end up trying it, then let me know how it went. Or if you find a more suitable method, let us know.
Regards,
Sara

0 Vote Up Vote Down
delmarcodiego answered 4 years ago

thank you Sara for your answer.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.