test sur reveiver

This commit is contained in:
Clement 2023-06-26 17:24:50 +02:00
parent 92cd2b3553
commit 1a66b59d1b
3 changed files with 126 additions and 7 deletions

View File

@ -1,7 +1,10 @@
#ifndef PROGRAM_H
#define PROGRAM_H
#include "Arduino.h"
#include <Arduino.h>
#include <LoRa.h>
#include <SPI.h>
#include <Wire.h>
class Program {
public:

View File

@ -3,6 +3,18 @@
Program::Program() {
// Startup
Serial.begin(MONITOR_SPEED);
Serial.println("initBoard");
SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN); //for LoRa module
Wire.begin(I2C_SDA, I2C_SCL);//for oled screen
// When the power is turned on, a delay is required.
delay(1500);
//init LoRa
LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DIO0_PIN);
if (!LoRa.begin(LoRa_frequency)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void Program::loop() {

View File

@ -1,11 +1,115 @@
#include "Program.h"
// #include "Program.h"
Program* program;
// Program* program;
void setup() {
program = new Program();
// void setup() {
// program = new Program();
// }
// void loop() {
// program->loop();
// }
#include <LoRa.h>
#include "boards.h"
#include <Arduino.h>
void setup()
{
initBoard();
// When the power is turned on, a delay is required.
delay(1500);
Serial.println("LoRa Receiver");
LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DIO0_PIN);
if (!LoRa.begin(LoRa_frequency)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
program->loop();
void loop()
{
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
String recv = "";
// read packet
while (LoRa.available()) {
recv += (char)LoRa.read();
}
Serial.println(recv);
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
#ifdef HAS_DISPLAY
if (u8g2) {
u8g2->clearBuffer();
char buf[256];
u8g2->drawStr(0, 12, "Received OK!");
u8g2->drawStr(0, 26, recv.c_str());
snprintf(buf, sizeof(buf), "RSSI:%i", LoRa.packetRssi());
u8g2->drawStr(0, 40, buf);
snprintf(buf, sizeof(buf), "SNR:%.1f", LoRa.packetSnr());
u8g2->drawStr(0, 56, buf);
u8g2->sendBuffer();
}
#endif
}
}
// #define HAS_DISPLAY
// #include <LoRa.h>
// #include "boards.h"
// int counter = 0;
// void setup()
// {
// initBoard();
// // When the power is turned on, a delay is required.
// delay(1500);
// Serial.println("LoRa Sender");
// LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DIO0_PIN);
// if (!LoRa.begin(LoRa_frequency)) {
// Serial.println("Starting LoRa failed!");
// while (1);
// }
// }
// void loop()
// {
// Serial.print("Sending packet: ");
// Serial.println(counter);
// // send packet
// LoRa.beginPacket();
// LoRa.print("hello ");
// LoRa.print(counter);
// LoRa.endPacket();
// #ifdef HAS_DISPLAY
// if (u8g2) {
// char buf[256];
// u8g2->clearBuffer();
// u8g2->drawStr(0, 12, "Transmitting: OK!");
// snprintf(buf, sizeof(buf), "Sending: %d", counter);
// u8g2->drawStr(0, 30, buf);
// u8g2->sendBuffer();
// }
// #endif
// counter++;
// delay(10000);
// }