kopia lustrzana https://github.com/lora-aprs/LoRa_APRS_iGate
display and NTP client added
rodzic
6c8cbb9daa
commit
f06bf716d5
|
@ -7,6 +7,7 @@
|
|||
#include <LoRa.h>
|
||||
|
||||
#include "settings.h"
|
||||
#include "display.h"
|
||||
|
||||
WiFiMulti WiFiMulti;
|
||||
WiFiUDP ntpUDP;
|
||||
|
@ -16,20 +17,26 @@ APRS_IS aprs_is(USER, PASS, TOOL, VERS);
|
|||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
init_display();
|
||||
|
||||
delay(500);
|
||||
Serial.println("[INFO] LoRa APRS iGate by OE5BPA (Peter Buchegger)");
|
||||
show_display_2("OE5BPA", "LoRa APRS iGate", "by Peter Buchegger", 2000);
|
||||
|
||||
WiFiMulti.addAP(WIFI_NAME, WIFI_KEY);
|
||||
Serial.print("[INFO] Waiting for WiFi");
|
||||
show_display_1("INFO", "Waiting for WiFi");
|
||||
while(WiFiMulti.run() != WL_CONNECTED)
|
||||
{
|
||||
Serial.print(".");
|
||||
show_display_2("INFO", "Waiting for WiFi", "....");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.println("[INFO] WiFi connected");
|
||||
Serial.print("[INFO] IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
show_display_2("INFO", "WiFi connected", "IP: ", 2000);
|
||||
|
||||
Serial.println("[INFO] Set SPI pins!");
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
|
@ -41,6 +48,7 @@ void setup()
|
|||
Serial.println(freq);
|
||||
if (!LoRa.begin(freq)) {
|
||||
Serial.println("[ERROR] Starting LoRa failed!");
|
||||
show_display_1("ERROR", "Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(12);
|
||||
|
@ -48,9 +56,16 @@ void setup()
|
|||
LoRa.setCodingRate4(5);
|
||||
LoRa.enableCrc();
|
||||
Serial.println("[INFO] LoRa init done!");
|
||||
show_display_1("INFO", "LoRa init done!", 2000);
|
||||
|
||||
timeClient.begin();
|
||||
if(!timeClient.forceUpdate())
|
||||
{
|
||||
Serial.println("[WARN] NTP Client force update issue!");
|
||||
show_display_1("WARN", "NTP Client force update issue!", 2000);
|
||||
}
|
||||
Serial.println("[INFO] NTP Client init done!");
|
||||
show_display_1("INFO", "NTP Client init done!", 2000);
|
||||
|
||||
delay(500);
|
||||
}
|
||||
|
@ -61,6 +76,7 @@ void loop()
|
|||
if(WiFiMulti.run() != WL_CONNECTED)
|
||||
{
|
||||
Serial.println("[ERROR] WiFi not connected!");
|
||||
show_display_1("ERROR", "WiFi not connected!");
|
||||
delay(1000);
|
||||
return;
|
||||
}
|
||||
|
@ -70,19 +86,32 @@ void loop()
|
|||
Serial.print(SERVER);
|
||||
Serial.print(" on port: ");
|
||||
Serial.println(PORT);
|
||||
//show_display_3("INFO", "Connecting to server", SERVER, PORT, 2000);
|
||||
show_display_1("INFO", "Connecting to server", 2000);
|
||||
if(!aprs_is.connect(SERVER, PORT, FILTER))
|
||||
{
|
||||
Serial.println("[ERROR] Connection failed.");
|
||||
Serial.println("[INFO] Waiting 5 seconds before retrying...");
|
||||
show_display_2("ERROR", "Server connection failed!", "waiting 5 sec");
|
||||
delay(5000);
|
||||
return;
|
||||
}
|
||||
Serial.println("[INFO] Connected to server!");
|
||||
}
|
||||
static int update_min = -99;
|
||||
if(timeClient.getMinutes() > update_min + BROADCAST_TIMEOUT)
|
||||
{
|
||||
show_display_1(call, "Broadcast to Server...", 2000);
|
||||
Serial.print("[" + timeClient.getFormattedTime() + "] ");
|
||||
aprs_is.sendMessage(BROADCAST_MESSAGE);
|
||||
update_min = timeClient.getMinutes();
|
||||
}
|
||||
if(aprs_is.available() > 0)
|
||||
{
|
||||
String str = aprs_is.getMessage();
|
||||
Serial.print("[" + timeClient.getFormattedTime() + "] ");
|
||||
Serial.println(aprs_is.getMessage());
|
||||
Serial.println(str);
|
||||
show_display_2(call, timeClient.getFormattedTime(), str, 0);
|
||||
}
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if(packetSize)
|
||||
|
@ -105,5 +134,7 @@ void loop()
|
|||
Serial.print("[INFO] ");
|
||||
Serial.println(msg.toString());*/
|
||||
aprs_is.sendMessage(str);
|
||||
|
||||
show_display_4(call, timeClient.getFormattedTime(), "RSSI: " + String(LoRa.packetRssi()), "SNR: " + String(LoRa.packetSnr()), str, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 init_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_1(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_2(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_3(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_4(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_5(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);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
#ifndef DISPLAY_H_
|
||||
#define DISPLAY_H_
|
||||
|
||||
void init_display();
|
||||
|
||||
void show_display(String header, int wait = 0);
|
||||
void show_display_1(String header, String line1, int wait = 0);
|
||||
void show_display_2(String header, String line1, String line2, int wait = 0);
|
||||
void show_display_3(String header, String line1, String line2, String line3, int wait = 0);
|
||||
void show_display_4(String header, String line1, String line2, String line3, String line4, int wait = 0);
|
||||
void show_display_5(String header, String line1, String line2, String line3, String line4, String line5, int wait = 0);
|
||||
|
||||
#endif
|
|
@ -5,7 +5,7 @@
|
|||
#define WIFI_NAME ""
|
||||
#define WIFI_KEY ""
|
||||
|
||||
#define USER ""
|
||||
#define USER "OE5BPA-10"
|
||||
#define PASS ""
|
||||
#define TOOL "ESP32-APRS-IS"
|
||||
#define VERS "0.1"
|
||||
|
@ -15,6 +15,7 @@
|
|||
//#define SERVER "euro.aprs2.net"
|
||||
#define PORT 14580
|
||||
|
||||
// LoRa Pins:
|
||||
#define SCK 5
|
||||
#define MISO 19
|
||||
#define MOSI 27
|
||||
|
@ -22,4 +23,9 @@
|
|||
#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
|
||||
|
|
Ładowanie…
Reference in New Issue