Browse Source

Merge pull request #6 from Qyon/master_sq9mdd

Code cleanup, bt support
pull/11/head
Rysiek Labus 1 year ago committed by GitHub
parent
commit
bb29af02cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 103
      src/TTGO_T-Beam_LoRa_APRS.ino
  2. 1
      src/TTGO_T-Beam_LoRa_APRS_config.h

103
src/TTGO_T-Beam_LoRa_APRS.ino

@ -23,6 +23,10 @@
#include <axp20x.h>
#include <KISS_TO_TNC2.h>
#ifdef ENABLE_BLUETOOTH
#include "BluetoothSerial.h"
#endif
// I2C LINES
#define I2C_SDA 21
#define I2C_SCL 22
@ -31,7 +35,11 @@
#define SSD1306_ADDRESS 0x3C
//other global Variables
String Textzeile1, Textzeile2, content;
String Textzeile1, Textzeile2;
#ifdef KISS_PROTOCOLL
String inTNCData = "";
#endif
int button=0;
int button_ctr=0;
@ -102,8 +110,12 @@ void batt_read(void);
void writedisplaytext(String, String, String, String, String, String, int);
void setup_data(void);
void displayInvalidGPS();
void handleKISSData(char character);
// SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
HardwareSerial ss(1); // TTGO has HW serial
HardwareSerial gpsSerial(1); // TTGO has HW serial
TinyGPSPlus gps; // The TinyGPS++ object
AXP20X_Class axp;
@ -118,6 +130,10 @@ BG_RF95 rf95(18, 26); // TTGO T-Beam has NSS @ Pin 18 and Interrupt IO @
#define OLED_RESET 4 // not used
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
#ifdef ENABLE_BLUETOOTH
BluetoothSerial SerialBT;
#endif
// + FUNCTIONS-----------------------------------------------------------+//
// This custom version of delay() ensures that the gps object
@ -129,8 +145,8 @@ static void smartDelay(unsigned long ms){
#endif
unsigned long start = millis();
do{
while (ss.available())
gps.encode(ss.read());
while (gpsSerial.available())
gps.encode(gpsSerial.read());
} while (millis() - start < ms);
}
@ -218,8 +234,17 @@ void recalcGPS(){
outString += String(BattVolts,2);
outString += ("V");
#endif
#ifdef KISS_PROTOCOLL
Serial.print(encode_kiss(outString));
#ifdef ENABLE_BLUETOOTH
if (SerialBT.connected()){
SerialBT.print(encode_kiss(outString));
}
#endif
Serial.print(outString);
#else
Serial.println(outString);
#endif
}
void sendpacket(){
@ -243,7 +268,7 @@ void sendpacket(){
}
}
void loraSend(byte lora_LTXStart, byte lora_LTXEnd, byte lora_LTXPacketType, byte lora_LTXDestination, byte lora_LTXSource, long lora_LTXTimeout, byte lora_LTXPower, float lora_FREQ, String message){
void loraSend(byte lora_LTXStart, byte lora_LTXEnd, byte lora_LTXPacketType, byte lora_LTXDestination, byte lora_LTXSource, long lora_LTXTimeout, byte lora_LTXPower, float lora_FREQ, const String& message){
byte i;
byte ltemp;
@ -333,7 +358,7 @@ void setup(){
max_time_to_nextTX=nextTX;
}
writedisplaytext("LoRa-APRS","","Init:","RF95 OK!","","",250);
ss.begin(GPSBaud, SERIAL_8N1, TXPin, RXPin); //Startup HW serial for GPS
gpsSerial.begin(GPSBaud, SERIAL_8N1, TXPin, RXPin); //Startup HW serial for GPS
writedisplaytext("LoRa-APRS","","Init:","GPS Serial OK!","","",250);
writedisplaytext(" "+Tcall,"","Init:","Waiting for GPS","","",250);
while (millis() < 5000 && gps.charsProcessed() < 10) {}
@ -347,6 +372,10 @@ void setup(){
rf95.setModemConfig(BG_RF95::Bw125Cr45Sf4096); // hard coded because of double definition
rf95.setTxPower(20); // was 5
delay(250);
#ifdef ENABLE_BLUETOOTH
SerialBT.begin(String("TTGO LORA APRS ") + CALLSIGN);
writedisplaytext("LoRa-APRS","","Init:","BT OK!","","",250);
#endif
writedisplaytext("LoRa-APRS","","Init:","FINISHED OK!"," =:-) ","",250);
writedisplaytext("","","","","","",0);
}
@ -356,20 +385,24 @@ void setup(){
// +---------------------------------------------------------------------+//
void loop() {
while (ss.available() > 0) {
gps.encode(ss.read());
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
}
#ifdef KISS_PROTOCOLL
while (Serial.available() > 0 ){
char character = Serial.read();
content.concat(character);
if (character == (char)FEND && content.length() > 3){
loraSend(lora_TXStart, lora_TXEnd, 60, 255, 1, 10, TXdbmW, TXFREQ, decode_kiss(content));
writedisplaytext("(KISSTX))","","","","","",1);
content = "";
}
handleKISSData(character);
}
#ifdef ENABLE_BLUETOOTH
if (SerialBT.connected()) {
while (SerialBT.available() > 0 ){
char character = SerialBT.read();
handleKISSData(character);
}
}
#endif
#endif
if (rf95.waitAvailableTimeout(100)) {
@ -467,23 +500,37 @@ void loop() {
Serial.print(String(BattVolts,1));
digitalWrite(TXLED, LOW);
#endif
} else{
writedisplaytext(" "+Tcall,"(TX) at valid GPS","LAT: not valid","LON: not valid","SPD: --- CRS: ---","SAT: "+String(gps.satellites.value()) + " BAT: "+String(BattVolts,1) +"V",1);
#ifdef SHOW_GPS_DATA
Serial.print("(TX) at valid GPS / LAT: not valid / Lon: not valid / SPD: --- / CRS: ---");
Serial.print(" / SAT: ");
Serial.print(String(gps.satellites.value()));
Serial.print(" / BAT: ");
Serial.println(String(BattVolts,1));
#endif
}
} else {
displayInvalidGPS();
}
}else{
if (gps.location.age() < 2000) {
writedisplaytext(" "+Tcall,"Time to TX: "+String(((lastTX+nextTX)-millis())/1000)+"sec","LAT: "+LatShown,"LON: "+LongShown,"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),1),"SAT: "+String(gps.satellites.value()) + " BAT: "+String(BattVolts,1) +"V",1);
}
} else {
displayInvalidGPS();
}
}
}
void handleKISSData(char character) {
inTNCData.concat(character);
if (character == (char)FEND && inTNCData.length() > 3){
writedisplaytext("(KISSTX))","","","","","",1);
loraSend(lora_TXStart, lora_TXEnd, 60, 255, 1, 10, TXdbmW, TXFREQ, decode_kiss(inTNCData));
inTNCData = "";
}
//smartDelay(900);
}
void displayInvalidGPS() {
writedisplaytext(" " + Tcall, "(TX) at valid GPS", "LAT: not valid", "LON: not valid", "SPD: --- CRS: ---", "SAT: " + String(gps.satellites.value()) + " BAT: " + String(BattVolts, 1) + "V", 1);
#ifdef SHOW_GPS_DATA
Serial.print("(TX) at valid GPS / LAT: not valid / Lon: not valid / SPD: --- / CRS: ---");
Serial.print(" / SAT: ");
Serial.print(String(gps.satellites.value()));
Serial.print(" / BAT: ");
Serial.println(String(BattVolts,1));
#endif
}
// end of main loop

1
src/TTGO_T-Beam_LoRa_APRS_config.h

@ -18,5 +18,6 @@
#define TXFREQ 433.775 // Transmit frequency in MHz
#define TXdbmW 20 // Transmit power in dBm 17-50mW, 18-63mW, 19-80mW, 20-100mW
//#define SHOW_GPS_DATA // uncomment to show on serial port, received data from GPS and debug information
#define ENABLE_BLUETOOTH
unsigned long max_time_to_nextTX = 180000L; // TRANSMIT INTERVAL set here MAXIMUM time in ms(!) for smart beaconing - minimum time is always 1 min = 60 secs = 60000L !!!
Loading…
Cancel
Save