Hallo zusammen,
hier meine Testprogramme für den Client und den Server.
Bei Interesse sende ich euch gern meine Library "myLora.h" per Mail.
Viele Grüße
Rolf
// ------------------------------------------------------------------------
// Siggis Windensteuerung
// written by : Rolf Kurth in 2023
//
rolf.kurth@cron-consulting.de
//
https://www.cron-consulting.de/
// ------------------------------------------------------------------------
//
https://www.arduino.cc/reference/de/
//
https://github.com/sandeepmistry/arduino-LoRa
// ------------------------------------------------------------------------
#include "myLora.h"
String ingoing;
String outgoing; // outgoing message
long lastSendTime = 0; // last send time
int interval = 3000; // interval between sends
LoRaWinde myLora; // constructor
//-------------------------------------------------------------------
void setup()
//-------------------------------------------------------------------
{
Serial.begin(115200);
while (!Serial)
;
myLora.init();
Serial.println("LoRa init succeeded.");
// register the receive callback
LoRa.onReceive(onReceive);
// put the radio into receive mode
LoRa.receive();
}
//-------------------------------------------------------------------
void loop()
//-------------------------------------------------------------------
{
LoRa.receive(); // put the radio into receive mode
// Serial.println("test");
}
//-------------------------------------------------------------------
void onReceive(int packetSize)
//-------------------------------------------------------------------
{
if (myLora.receive(packetSize, ingoing)) {
;
Serial.print("Got ");
Serial.println(ingoing);
myLora.ServerMapToData(ingoing);
Serial.print(myLora.TxRec.status);
Serial.println(myLora.TxRec.value);
// status; VoltageAkt; CurrentMax; TemperaturAkt; Seilspannung;
myLora.ServerSendReply("S ", 24.3, 60.0, 23.7, 120);
}
}
// ------------------------------------------------------------------------
// Siggis Windensteuerung
// written by : Rolf Kurth in 2023
//
rolf.kurth@cron-consulting.de
//
https://www.cron-consulting.de/
// ------------------------------------------------------------------------
//
https://www.arduino.cc/reference/de/
//
https://github.com/sandeepmistry/arduino-LoRa
// ------------------------------------------------------------------------
#include "myLora.h"
String outgoing; // outgoing message
String ingoing; // outgoing message
volatile int count;
long lastSendTime = 0; // last send time
int interval = 2000; // interval between sends
LoRaWinde myLora; // constructor
//-------------------------------------------------------------------
void setup()
//-------------------------------------------------------------------
{
Serial.begin(115200); // initialize serial
while (!Serial)
;
myLora.init();
Serial.println("LoRa init succeeded.");
}
//-------------------------------------------------------------------
void loop()
//-------------------------------------------------------------------
{
if (millis() - lastSendTime > interval) {
myLora.ClientSendMessage("ST", 120);
myLora.ClientSendString("ST,120");
lastSendTime = millis(); // timestamp the message
interval = random(2000) + 1000; // 2-3 seconds
}
LoRa.onTxDone(onTxDone);
// parse for a packet, and call onReceive with the result:
onReceive(LoRa.parsePacket());
}
//-------------------------------------------------------------------
void onReceive(int packetSize)
//-------------------------------------------------------------------
{
if (myLora.receive(packetSize, ingoing)) {
myLora.ClientMapToData(ingoing);
PrintRec();
}
}
//-------------------------------------------------------------------
void PrintRec()
//-------------------------------------------------------------------
{
Serial.println("------------------------------------- ");
Serial.print("Got Reply ");
Serial.print(myLora.ReplyRec.status);
Serial.print("\t");
Serial.print(myLora.ReplyRec.VoltageAkt);
Serial.print("\t");
Serial.print(myLora.ReplyRec.CurrentMax);
Serial.print("\t");
Serial.print(myLora.ReplyRec.TemperaturAkt);
Serial.print("\t");
Serial.println(myLora.ReplyRec.Seilspannung);
}
//-------------------------------------------------------------------
void onTxDone()
//-------------------------------------------------------------------
{
// put the radio into receive mode
// Serial.println("Tx Done");
count++;
// LoRa.receive();
}