test sur reveiver
This commit is contained in:
parent
92cd2b3553
commit
1a66b59d1b
@ -1,7 +1,10 @@
|
|||||||
#ifndef PROGRAM_H
|
#ifndef PROGRAM_H
|
||||||
#define PROGRAM_H
|
#define PROGRAM_H
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include <Arduino.h>
|
||||||
|
#include <LoRa.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
public:
|
public:
|
||||||
|
@ -3,6 +3,18 @@
|
|||||||
Program::Program() {
|
Program::Program() {
|
||||||
// Startup
|
// Startup
|
||||||
Serial.begin(MONITOR_SPEED);
|
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() {
|
void Program::loop() {
|
||||||
|
@ -1,11 +1,115 @@
|
|||||||
#include "Program.h"
|
// #include "Program.h"
|
||||||
|
|
||||||
Program* program;
|
// Program* program;
|
||||||
|
|
||||||
void setup() {
|
// void setup() {
|
||||||
program = new Program();
|
// 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() {
|
void loop()
|
||||||
program->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);
|
||||||
|
// }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user