mirror of
https://github.com/lora-aprs/LoRa_APRS_iGate.git
synced 2026-04-09 00:14:53 +00:00
moved to platformio
This commit is contained in:
parent
c30207ce9b
commit
8fd16594d8
7 changed files with 92 additions and 0 deletions
205
src/LoRa_APRS_iGate.cpp
Normal file
205
src/LoRa_APRS_iGate.cpp
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
#include <Arduino.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <NTPClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <LoRa.h>
|
||||
#include <APRS-IS.h>
|
||||
#include <APRS-Decoder.h>
|
||||
|
||||
#include "settings.h"
|
||||
#include "display.h"
|
||||
|
||||
WiFiMulti WiFiMulti;
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, 60*60);
|
||||
APRS_IS aprs_is(USER, PASS, TOOL, VERS);
|
||||
|
||||
int next_update = -1;
|
||||
|
||||
void setup_wifi();
|
||||
void setup_ota();
|
||||
void setup_lora();
|
||||
void setup_ntp();
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
setup_display();
|
||||
|
||||
delay(500);
|
||||
Serial.println("[INFO] LoRa APRS iGate by OE5BPA (Peter Buchegger)");
|
||||
show_display("OE5BPA", "LoRa APRS iGate", "by Peter Buchegger", 2000);
|
||||
|
||||
setup_wifi();
|
||||
setup_ota();
|
||||
setup_lora();
|
||||
setup_ntp();
|
||||
|
||||
delay(500);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
timeClient.update();
|
||||
ArduinoOTA.handle();
|
||||
if(WiFiMulti.run() != WL_CONNECTED)
|
||||
{
|
||||
Serial.println("[ERROR] WiFi not connected!");
|
||||
show_display("ERROR", "WiFi not connected!");
|
||||
delay(1000);
|
||||
return;
|
||||
}
|
||||
if(!aprs_is.connected())
|
||||
{
|
||||
Serial.print("[INFO] connecting to server: ");
|
||||
Serial.print(SERVER);
|
||||
Serial.print(" on port: ");
|
||||
Serial.println(PORT);
|
||||
//show_display("INFO", "Connecting to server", SERVER, PORT, 2000);
|
||||
show_display("INFO", "Connecting to server");
|
||||
if(!aprs_is.connect(SERVER, PORT, FILTER))
|
||||
{
|
||||
Serial.println("[ERROR] Connection failed.");
|
||||
Serial.println("[INFO] Waiting 5 seconds before retrying...");
|
||||
show_display("ERROR", "Server connection failed!", "waiting 5 sec");
|
||||
delay(5000);
|
||||
return;
|
||||
}
|
||||
Serial.println("[INFO] Connected to server!");
|
||||
}
|
||||
if(next_update == timeClient.getMinutes() || next_update == -1)
|
||||
{
|
||||
show_display(call, "Broadcast to Server...");
|
||||
Serial.print("[" + timeClient.getFormattedTime() + "] ");
|
||||
aprs_is.sendMessage(BROADCAST_MESSAGE);
|
||||
next_update = (timeClient.getMinutes() + BROADCAST_TIMEOUT) % 60;
|
||||
}
|
||||
if(aprs_is.available() > 0)
|
||||
{
|
||||
String str = aprs_is.getMessage();
|
||||
Serial.print("[" + timeClient.getFormattedTime() + "] ");
|
||||
Serial.println(str);
|
||||
show_display(call, timeClient.getFormattedTime(), str, 0);
|
||||
}
|
||||
if(LoRa.parsePacket())
|
||||
{
|
||||
String str;
|
||||
Serial.print("[" + timeClient.getFormattedTime() + "] ");
|
||||
Serial.print(" Received packet '");
|
||||
while(LoRa.available())
|
||||
{
|
||||
str += (char)LoRa.read();
|
||||
}
|
||||
Serial.print(str);
|
||||
Serial.print("' with RSSI ");
|
||||
Serial.print(LoRa.packetRssi());
|
||||
Serial.print(" and SNR ");
|
||||
Serial.println(LoRa.packetSnr());
|
||||
|
||||
/*APRSMessage msg;
|
||||
msg.decode(str);
|
||||
Serial.print("[INFO] ");
|
||||
Serial.println(msg.toString());*/
|
||||
aprs_is.sendMessage(str);
|
||||
|
||||
show_display(call, timeClient.getFormattedTime(), "RSSI: " + String(LoRa.packetRssi()), "SNR: " + String(LoRa.packetSnr()), str, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void setup_wifi()
|
||||
{
|
||||
char hostname[] = "LoRaAPRSiGate";
|
||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||
WiFi.setHostname(hostname);
|
||||
WiFiMulti.addAP(WIFI_NAME, WIFI_KEY);
|
||||
Serial.print("[INFO] Waiting for WiFi");
|
||||
show_display("INFO", "Waiting for WiFi");
|
||||
while(WiFiMulti.run() != WL_CONNECTED)
|
||||
{
|
||||
Serial.print(".");
|
||||
show_display("INFO", "Waiting for WiFi", "....");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.println("[INFO] WiFi connected");
|
||||
Serial.print("[INFO] IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
show_display("INFO", "WiFi connected", "IP: ", WiFi.localIP().toString(), 2000);
|
||||
|
||||
MDNS.begin(hostname);
|
||||
}
|
||||
|
||||
void setup_ota()
|
||||
{
|
||||
ArduinoOTA
|
||||
.onStart([]()
|
||||
{
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem";
|
||||
Serial.println("Start updating " + type);
|
||||
show_display("OTA UPDATE", "Start update", type);
|
||||
})
|
||||
.onEnd([]()
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("End");
|
||||
})
|
||||
.onProgress([](unsigned int progress, unsigned int total)
|
||||
{
|
||||
Serial.print("Progress: ");
|
||||
Serial.print(progress / (total / 100));
|
||||
Serial.println("%");
|
||||
show_display("OTA UPDATE", "Progress: ", String(progress / (total / 100)) + "%");
|
||||
})
|
||||
.onError([](ota_error_t error) {
|
||||
Serial.print("Error[");
|
||||
Serial.print(error);
|
||||
Serial.print("]: ");
|
||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
}
|
||||
|
||||
void setup_lora()
|
||||
{
|
||||
Serial.println("[INFO] Set SPI pins!");
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
LoRa.setPins(SS, RST, DIO0);
|
||||
Serial.println("[INFO] Set LoRa pins!");
|
||||
|
||||
long freq = 433775000;
|
||||
Serial.print("[INFO] frequency: ");
|
||||
Serial.println(freq);
|
||||
if (!LoRa.begin(freq)) {
|
||||
Serial.println("[ERROR] Starting LoRa failed!");
|
||||
show_display("ERROR", "Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(12);
|
||||
LoRa.setSignalBandwidth(125E3);
|
||||
LoRa.setCodingRate4(5);
|
||||
LoRa.enableCrc();
|
||||
Serial.println("[INFO] LoRa init done!");
|
||||
show_display("INFO", "LoRa init done!", 2000);
|
||||
}
|
||||
|
||||
void setup_ntp()
|
||||
{
|
||||
timeClient.begin();
|
||||
if(!timeClient.forceUpdate())
|
||||
{
|
||||
Serial.println("[WARN] NTP Client force update issue!");
|
||||
show_display("WARN", "NTP Client force update issue!", 2000);
|
||||
}
|
||||
Serial.println("[INFO] NTP Client init done!");
|
||||
show_display("INFO", "NTP Client init done!", 2000);
|
||||
}
|
||||
137
src/display.cpp
Normal file
137
src/display.cpp
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#include "display.h"
|
||||
|
||||
#define OLED_SDA 4
|
||||
#define OLED_SCL 15
|
||||
#define OLED_RST 16
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||
|
||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);
|
||||
|
||||
void setup_display()
|
||||
{
|
||||
pinMode(OLED_RST, OUTPUT);
|
||||
digitalWrite(OLED_RST, LOW);
|
||||
delay(20);
|
||||
digitalWrite(OLED_RST, HIGH);
|
||||
|
||||
Wire.begin(OLED_SDA, OLED_SCL);
|
||||
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false))
|
||||
{
|
||||
Serial.println("SSD1306 allocation failed");
|
||||
while (1);
|
||||
}
|
||||
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(0,0);
|
||||
display.print("LORA SENDER ");
|
||||
display.display();
|
||||
}
|
||||
|
||||
void show_display(String header, int wait)
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(2);
|
||||
display.setCursor(0,0);
|
||||
display.println(header);
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
|
||||
void show_display(String header, String line1, int wait)
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(2);
|
||||
display.setCursor(0,0);
|
||||
display.println(header);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(0,16);
|
||||
display.println(line1);
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
|
||||
void show_display(String header, String line1, String line2, int wait)
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(2);
|
||||
display.setCursor(0,0);
|
||||
display.println(header);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(0,16);
|
||||
display.println(line1);
|
||||
display.setCursor(0,26);
|
||||
display.println(line2);
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
|
||||
void show_display(String header, String line1, String line2, String line3, int wait)
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(2);
|
||||
display.setCursor(0,0);
|
||||
display.println(header);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(0,16);
|
||||
display.println(line1);
|
||||
display.setCursor(0,26);
|
||||
display.println(line2);
|
||||
display.setCursor(0,36);
|
||||
display.println(line3);
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
|
||||
void show_display(String header, String line1, String line2, String line3, String line4, int wait)
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(2);
|
||||
display.setCursor(0,0);
|
||||
display.println(header);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(0,16);
|
||||
display.println(line1);
|
||||
display.setCursor(0,26);
|
||||
display.println(line2);
|
||||
display.setCursor(0,36);
|
||||
display.println(line3);
|
||||
display.setCursor(0,46);
|
||||
display.println(line4);
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
|
||||
void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait)
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(2);
|
||||
display.setCursor(0,0);
|
||||
display.println(header);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(0,16);
|
||||
display.println(line1);
|
||||
display.setCursor(0,26);
|
||||
display.println(line2);
|
||||
display.setCursor(0,36);
|
||||
display.println(line3);
|
||||
display.setCursor(0,46);
|
||||
display.println(line4);
|
||||
display.setCursor(0,56);
|
||||
display.println(line5);
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
14
src/display.h
Normal file
14
src/display.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
#ifndef DISPLAY_H_
|
||||
#define DISPLAY_H_
|
||||
|
||||
void setup_display();
|
||||
|
||||
void show_display(String header, int wait = 0);
|
||||
void show_display(String header, String line1, int wait = 0);
|
||||
void show_display(String header, String line1, String line2, int wait = 0);
|
||||
void show_display(String header, String line1, String line2, String line3, int wait = 0);
|
||||
void show_display(String header, String line1, String line2, String line3, String line4, int wait = 0);
|
||||
void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait = 0);
|
||||
|
||||
#endif
|
||||
31
src/settings.h
Normal file
31
src/settings.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#ifndef SETTINGS_H_
|
||||
#define SETTINGS_H_
|
||||
|
||||
#define WIFI_NAME ""
|
||||
#define WIFI_KEY ""
|
||||
|
||||
#define USER "OE5BPA-10"
|
||||
#define PASS ""
|
||||
#define TOOL "ESP32-APRS-IS"
|
||||
#define VERS "0.1"
|
||||
#define FILTER "r/48.29/14.29/25"
|
||||
|
||||
#define SERVER "austria.aprs2.net"
|
||||
//#define SERVER "euro.aprs2.net"
|
||||
#define PORT 14580
|
||||
|
||||
// LoRa Pins:
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DIO0 26
|
||||
|
||||
#define BROADCAST_TIMEOUT 15
|
||||
#define BROADCAST_MESSAGE "OE5BPA-10>APRS:=4819.82NI01418.68E&LoRa IGATE (test RX mode), Info: github.com/peterus/LoRa_APRS_iGate"
|
||||
|
||||
String call = "OE5BPA";
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue