kopia lustrzana https://github.com/sh123/esp32_loraprs
Added arduino sketch and loraprs modules
rodzic
fe99c592ba
commit
ed48819ae8
|
@ -0,0 +1,39 @@
|
||||||
|
#include "WiFi.h"
|
||||||
|
#include "loraprs.h"
|
||||||
|
|
||||||
|
#define LORAPRS_CLIENT
|
||||||
|
|
||||||
|
#define LORAPRS_FREQ 432.5E6
|
||||||
|
|
||||||
|
#ifdef LORAPRS_CLIENT
|
||||||
|
#define LORAPRS_BT_NAME "loraprs_client"
|
||||||
|
#define LORAPRS_WIFI_SSID ""
|
||||||
|
#define LORAPRS_WIFI_KEY ""
|
||||||
|
#define LORAPRS_LOGIN "NOCALL-0"
|
||||||
|
#define LORAPRS_PASS "00000"
|
||||||
|
#else
|
||||||
|
#define LORAPRS_BT_NAME "loraprs_server"
|
||||||
|
#define LORAPRS_WIFI_SSID "<mywifi>"
|
||||||
|
#define LORAPRS_WIFI_KEY "<key>"
|
||||||
|
#define LORAPRS_LOGIN "NOCALL-0"
|
||||||
|
#define LORAPRS_PASS "00000"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LoraPrs loraPrs(
|
||||||
|
LORAPRS_FREQ,
|
||||||
|
LORAPRS_BT_NAME,
|
||||||
|
LORAPRS_WIFI_SSID,
|
||||||
|
LORAPRS_WIFI_KEY,
|
||||||
|
LORAPRS_LOGIN,
|
||||||
|
LORAPRS_PASS);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
while (!Serial);
|
||||||
|
|
||||||
|
loraPrs.setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
loraPrs.loop();
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
#include "loraprs.h"
|
||||||
|
|
||||||
|
LoraPrs::LoraPrs(int loraFreq, String btName, String wifiName,
|
||||||
|
String wifiKey, String aprsLoginCallsign, String aprsPass)
|
||||||
|
: serialBt_()
|
||||||
|
, loraFreq_(loraFreq)
|
||||||
|
, btName_(btName)
|
||||||
|
, wifiName_(wifiName)
|
||||||
|
, wifiKey_(wifiKey)
|
||||||
|
{
|
||||||
|
aprsLogin_ = "";
|
||||||
|
aprsLogin_ += "user ";
|
||||||
|
aprsLogin_ += aprsLoginCallsign;
|
||||||
|
aprsLogin_ += " pass ";
|
||||||
|
aprsLogin_ += aprsPass;
|
||||||
|
aprsLogin_ += " vers ";
|
||||||
|
aprsLogin_ += CfgLoraprsVersion;
|
||||||
|
aprsLogin_ += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoraPrs::setup()
|
||||||
|
{
|
||||||
|
setupWifi(wifiName_, wifiKey_);
|
||||||
|
setupLora(loraFreq_);
|
||||||
|
setupBt(btName_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoraPrs::setupWifi(String wifiName, String wifiKey)
|
||||||
|
{
|
||||||
|
if (wifiName.length() != 0) {
|
||||||
|
Serial.print("WIFI connecting to " + wifiName);
|
||||||
|
|
||||||
|
WiFi.begin(wifiName.c_str(), wifiKey.c_str());
|
||||||
|
|
||||||
|
// TODO, add timeout
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.println("ok");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoraPrs::setupLora(int loraFreq)
|
||||||
|
{
|
||||||
|
Serial.print("LoRa init...");
|
||||||
|
|
||||||
|
LoRa.setPins(CfgPinSs, CfgPinRst, CfgPinDio0);
|
||||||
|
|
||||||
|
while (!LoRa.begin(loraFreq)) {
|
||||||
|
Serial.print(".");
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
LoRa.setSyncWord(CfgSync);
|
||||||
|
LoRa.setSpreadingFactor(CfgSpread);
|
||||||
|
LoRa.setSignalBandwidth(CfgBw);
|
||||||
|
LoRa.setTxPower(CfgPower);
|
||||||
|
|
||||||
|
Serial.println("ok");
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoraPrs::setupBt(String btName)
|
||||||
|
{
|
||||||
|
Serial.print("BT init " + btName + "...");
|
||||||
|
|
||||||
|
if (serialBt_.begin(btName)) {
|
||||||
|
Serial.println("ok");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println("failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoraPrs::loop()
|
||||||
|
{
|
||||||
|
if (serialBt_.available()) {
|
||||||
|
onBtReceived();
|
||||||
|
}
|
||||||
|
if (LoRa.parsePacket()) {
|
||||||
|
onLoraReceived();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoraPrs::onAprsReceived(String aprsMessage)
|
||||||
|
{
|
||||||
|
Serial.print(aprsMessage);
|
||||||
|
|
||||||
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
|
WiFiClient wifiClient;
|
||||||
|
|
||||||
|
if (!wifiClient.connect(CfgAprsHost.c_str(), CfgAprsPort)) {
|
||||||
|
Serial.println("Failed to connect to " + CfgAprsHost + ":" + CfgAprsPort);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wifiClient.print(aprsLogin_);
|
||||||
|
wifiClient.print(aprsMessage);
|
||||||
|
wifiClient.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoraPrs::onLoraReceived()
|
||||||
|
{
|
||||||
|
String buf;
|
||||||
|
while (LoRa.available()) {
|
||||||
|
char c = (char)LoRa.read();
|
||||||
|
if (c != '\n')
|
||||||
|
buf += c;
|
||||||
|
}
|
||||||
|
for (int i; i < buf.length(); i++) {
|
||||||
|
serialBt_.write((uint8_t)buf[i]);
|
||||||
|
}
|
||||||
|
onAprsReceived(buf + " " + String(LoRa.packetSnr()) + "dB\n");
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoraPrs::onBtReceived()
|
||||||
|
{
|
||||||
|
LoRa.beginPacket();
|
||||||
|
while (serialBt_.available()) {
|
||||||
|
char c = (char)serialBt_.read();
|
||||||
|
LoRa.print(c);
|
||||||
|
}
|
||||||
|
LoRa.endPacket();
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
#ifndef LORAPRS_H
|
||||||
|
#define LORAPRS_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <LoRa.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
#include "BluetoothSerial.h"
|
||||||
|
|
||||||
|
class LoraPrs
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const String CfgLoraprsVersion = "LoRAPRS 0.1";
|
||||||
|
|
||||||
|
const byte CfgPinSs = 5;
|
||||||
|
const byte CfgPinRst = 26;
|
||||||
|
const byte CfgPinDio0 = 14;
|
||||||
|
|
||||||
|
const int CfgBw = 20e3;
|
||||||
|
const byte CfgSpread = 9;
|
||||||
|
const byte CfgSync = 0xf3;
|
||||||
|
const byte CfgPower = 20;
|
||||||
|
|
||||||
|
const int CfgAprsPort = 14580;
|
||||||
|
const String CfgAprsHost = "rotate.aprs2.net";
|
||||||
|
|
||||||
|
public:
|
||||||
|
LoraPrs(int freq, String btName, String wifiName,
|
||||||
|
String wifiKey, String aprsLoginCallsign, String aprsPass);
|
||||||
|
|
||||||
|
void setup();
|
||||||
|
void loop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupWifi(String wifiName, String wifiKey);
|
||||||
|
void setupLora(int loraFreq);
|
||||||
|
void setupBt(String btName);
|
||||||
|
|
||||||
|
void onLoraReceived();
|
||||||
|
void onBtReceived();
|
||||||
|
void onAprsReceived(String aprsMessage);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BluetoothSerial serialBt_;
|
||||||
|
|
||||||
|
int loraFreq_;
|
||||||
|
String btName_;
|
||||||
|
String wifiName_;
|
||||||
|
String wifiKey_;
|
||||||
|
String aprsLogin_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LORAPRS_H
|
Ładowanie…
Reference in New Issue