store mode in NVS
parent
dd42e157ab
commit
d9f2ea6a85
|
@ -20,22 +20,19 @@
|
|||
|
||||
#include <TTGO_T-Beam_LoRa_APRS_config.h> // to config user parameters
|
||||
#include <Arduino.h>
|
||||
#include <Preferences.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <SPI.h>
|
||||
#include <BG_RF95.h> // library from OE1ACM
|
||||
// #include <string>
|
||||
|
||||
#include <TinyGPS++.h>
|
||||
// #include <SoftwareSerial.h>
|
||||
#include <math.h>
|
||||
//#include <DHT.h>
|
||||
#include <DHTesp.h> // library from https://github.com/beegee-tokyo/DHTesp
|
||||
#include <driver/adc.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <splash.h>
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SPITFT.h>
|
||||
#include <Adafruit_SPITFT_Macros.h>
|
||||
|
@ -57,6 +54,14 @@ float temp=99.99; //Stores temperature value
|
|||
|
||||
//other global Variables
|
||||
String Textzeile1, Textzeile2;
|
||||
int button=0;
|
||||
int button_ctr=0;
|
||||
|
||||
enum Tx_Mode {TRACKER, WX_TRACKER, WX_MOVE, WX_FIXED};
|
||||
// Position from GPS for TRACKER and WX_TRACKER
|
||||
// Position for WX_ONLY from Headerfile!!!
|
||||
|
||||
Tx_Mode tracker_mode;
|
||||
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
//PINs used for HW extensions
|
||||
|
@ -72,6 +77,7 @@ const byte TX_en = 0;
|
|||
const byte RX_en = 0; //TX/RX enable 1W modul
|
||||
|
||||
const byte TXLED = 14; //pin number for LED on TX Tracker
|
||||
const byte BUTTON = 39; //pin number for Button on TTGO T-Beam
|
||||
// const byte GPSLED = 6; // pin gps & Heartbeat
|
||||
// const byte GPSLED1 = 9; // pin gps & Heartbeat
|
||||
|
||||
|
@ -88,16 +94,13 @@ const byte lora_PNSS = 18; //pin number where the NSS line for the LoRa device
|
|||
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
|
||||
|
||||
// Variables and Constants
|
||||
Preferences prefs;
|
||||
|
||||
String InputString = ""; //data on buff is copied to this string
|
||||
String Outputstring = "";
|
||||
String outString=""; //The new Output String with GPS Conversion RAW
|
||||
|
||||
#if (FIXED_POSITION)
|
||||
boolean wx = true;
|
||||
#else
|
||||
boolean wx = false;
|
||||
#endif
|
||||
boolean wx;
|
||||
|
||||
//byte arrays
|
||||
byte lora_TXBUFF[128]; //buffer for packet to send
|
||||
|
@ -117,7 +120,6 @@ unsigned long lastTX = 0L;
|
|||
|
||||
float BattVolts;
|
||||
|
||||
static adc1_channel_t adc_channel = ADC1_GPIO35_CHANNEL;
|
||||
static const adc_atten_t atten = ADC_ATTEN_DB_6;
|
||||
static const adc_unit_t unit = ADC_UNIT_1;
|
||||
|
||||
|
@ -126,13 +128,10 @@ void recalcGPS(void);
|
|||
void sendpacket(void);
|
||||
void loraSend(byte, byte, byte, byte, byte, long, byte, float);
|
||||
void batt_read(void);
|
||||
void writedisplaytext(String, String, String, String, String, int);
|
||||
void writedisplaytext(String, String, String, String, String, String, int);
|
||||
|
||||
|
||||
// #if (SEND_WX)
|
||||
// DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino
|
||||
DHTesp dht;
|
||||
// #endif
|
||||
|
||||
// SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
|
||||
HardwareSerial ss(1); // TTGO has HW serial
|
||||
|
@ -152,35 +151,74 @@ Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
|
|||
|
||||
void setup()
|
||||
{
|
||||
prefs.begin("nvs", false);
|
||||
tracker_mode = (Tx_Mode)prefs.getChar("tracker_mode", 0);
|
||||
prefs.end();
|
||||
//tracker_mode = current_mode;
|
||||
/////////////////
|
||||
// hier muss aus dem RAM der Modus gelesen werden!
|
||||
/////////////////
|
||||
if (tracker_mode == WX_TRACKER) {
|
||||
wx = true;
|
||||
} else {
|
||||
wx = false;
|
||||
}
|
||||
|
||||
pinMode(TXLED, OUTPUT);
|
||||
pinMode(BUTTON, INPUT);
|
||||
|
||||
digitalWrite(TXLED, LOW); // turn blue LED off
|
||||
Serial.begin(115200);
|
||||
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
|
||||
for(;;); // Don't proceed, loop forever
|
||||
}
|
||||
digitalWrite(TXLED, HIGH);
|
||||
writedisplaytext("","Init:","Display OK!","","",1000);
|
||||
writedisplaytext("LoRa - APRS","","Init:","Display OK!","","",1000);
|
||||
digitalWrite(TXLED, LOW);
|
||||
Serial.println("Init: Display OK!");
|
||||
if (!rf95.init()) {
|
||||
|
||||
switch(tracker_mode) {
|
||||
case TRACKER:
|
||||
writedisplaytext("LoRa - APRS","","Init:","Mode","TRACKER","",1000);
|
||||
Serial.println("Init: Mode TRACKER");
|
||||
break;
|
||||
case WX_MOVE:
|
||||
writedisplaytext("LoRa - APRS","","Init:","Mode","WX_MOVE","",1000);
|
||||
Serial.println("Init: Mode WX only - moving");
|
||||
break;
|
||||
case WX_FIXED:
|
||||
writedisplaytext("LoRa - APRS","","Init:","Mode","WX_FIXED","(no GPS used)",1000);
|
||||
Serial.println("Init: Mode WX only - fixed Pos");
|
||||
break;
|
||||
case WX_TRACKER:
|
||||
writedisplaytext("LoRa - APRS","","Init:","Mode","WX & TRACKER","",1000);
|
||||
Serial.println("Init: Mode WX & TRACKER");
|
||||
break;
|
||||
default:
|
||||
writedisplaytext("LoRa - APRS","","Init:","Mode","UNKNOWN","STOPPED",1000);
|
||||
Serial.println("Init: Mode UNKNOWN STOPPED!!!!");
|
||||
while (true) {}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!rf95.init()) {
|
||||
// Serial.println("init failed");
|
||||
|
||||
writedisplaytext("","Init:","RF95 FAILED!",":-(","",1000);
|
||||
writedisplaytext("LoRa - APRS","","Init:","RF95 FAILED!",":-(","",1000);
|
||||
Serial.println("Init: RF95 FAILED!");
|
||||
for(;;); // Don't proceed, loop forever
|
||||
}
|
||||
|
||||
digitalWrite(TXLED, HIGH);
|
||||
writedisplaytext("","Init:","RF95 OK!","","",1000);
|
||||
writedisplaytext("LoRa - APRS","","Init:","RF95 OK!","","",1000);
|
||||
digitalWrite(TXLED, LOW);
|
||||
Serial.println("Init: RF95 OK!");
|
||||
|
||||
#if !(FIXED_POSITION)
|
||||
if (tracker_mode != WX_FIXED) {
|
||||
ss.begin(GPSBaud, SERIAL_8N1, 12, 15); //Startup HW serial for GPS
|
||||
#endif // #if !(FIXED_POSITION)
|
||||
}
|
||||
digitalWrite(TXLED, HIGH);
|
||||
writedisplaytext("","Init:","GPS Serial OK!","","",1000);
|
||||
writedisplaytext("LoRa - APRS","","Init:","GPS Serial OK!","","",1000);
|
||||
digitalWrite(TXLED, LOW);
|
||||
Serial.println("Init: GPS Serial OK!");
|
||||
|
||||
|
@ -190,7 +228,7 @@ void setup()
|
|||
adc1_config_width(ADC_WIDTH_BIT_12);
|
||||
adc1_config_channel_atten(ADC1_CHANNEL_7,ADC_ATTEN_DB_6);
|
||||
// adc1_config_channel_atten(adc_channel, atten);
|
||||
writedisplaytext("","Init:","ADC OK!",String(analogRead(35)*7.221/4096,4),"",1000);
|
||||
writedisplaytext("LoRa - APRS","","Init:","ADC OK!","BAT: "+String(analogRead(35)*7.221/4096,1),"",1000);
|
||||
Serial.println("Init: ADC OK!");
|
||||
|
||||
rf95.setFrequency(433.775);
|
||||
|
@ -200,28 +238,21 @@ void setup()
|
|||
//rf95.printRegisters();
|
||||
//rf95.setPromiscuousbg();
|
||||
|
||||
//#if (SEND_WX)
|
||||
//dht.begin(); // DHT22 initialisieren
|
||||
dht.setup(DHTPIN,dht.AUTO_DETECT);
|
||||
dht.setup(DHTPIN,dht.AUTO_DETECT); // initialize DHT22
|
||||
delay(250);
|
||||
//temp = dht.readTemperature();
|
||||
temp = dht.getTemperature();
|
||||
hum = dht.getHumidity();
|
||||
writedisplaytext("","Init:","DHT OK!","TEMP: "+String(temp),"HUM: "+String(hum),750);
|
||||
writedisplaytext("LoRa - APRS","","Init:","DHT OK!","TEMP: "+String(temp,1),"HUM: "+String(hum,1),750);
|
||||
Serial.print("Init: DHT OK! Temp=");
|
||||
Serial.print(String(temp));
|
||||
Serial.print(" Hum=");
|
||||
Serial.println(String(hum));
|
||||
//#else //#if (SEND_WX)
|
||||
// writedisplaytext("","Init:","no DHT configuration","","",1000);
|
||||
// Serial.println("Init: no DHT configuration");
|
||||
//#endif //#if (SEND_WX)
|
||||
|
||||
digitalWrite(TXLED, HIGH);
|
||||
writedisplaytext("","Init:","All DONE OK!",":-D","",1000);
|
||||
digitalWrite(TXLED, LOW);
|
||||
Serial.println("Init: ALL DONE OK! :-D");
|
||||
writedisplaytext("","","","","",0);
|
||||
digitalWrite(TXLED, HIGH);
|
||||
writedisplaytext("LoRa - APRS","","Init:","All DONE OK!",":-D","",1000);
|
||||
digitalWrite(TXLED, LOW);
|
||||
Serial.println("Init: ALL DONE OK! :-D");
|
||||
writedisplaytext("","","","","","",0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -229,12 +260,38 @@ writedisplaytext("","","","","",0);
|
|||
|
||||
void loop()
|
||||
{
|
||||
if (hum_temp)
|
||||
{
|
||||
if (digitalRead(BUTTON)==LOW) {
|
||||
++button_ctr;
|
||||
if (button_ctr>=3){
|
||||
switch(tracker_mode) {
|
||||
case TRACKER:
|
||||
tracker_mode = WX_TRACKER;
|
||||
writedisplaytext("LoRa - APRS","","New Mode","WX-TRACKER","","",1000);
|
||||
break;
|
||||
case WX_TRACKER:
|
||||
tracker_mode = WX_MOVE;
|
||||
writedisplaytext("LoRa - APRS","","New Mode","WX-MOVING","","",1000);
|
||||
break;
|
||||
case WX_MOVE:
|
||||
tracker_mode = WX_FIXED;
|
||||
writedisplaytext("LoRa - APRS","","New Mode","WX-FIXED","","",1000);
|
||||
break;
|
||||
case WX_FIXED:
|
||||
default:
|
||||
tracker_mode = TRACKER;
|
||||
writedisplaytext("LoRa - APRS","","New Mode","TRACKER","","",1000);
|
||||
break;
|
||||
}
|
||||
prefs.begin("nvs", false);
|
||||
prefs.putChar("tracker_mode", (char)tracker_mode);
|
||||
prefs.end();
|
||||
button_ctr=0;
|
||||
}
|
||||
}
|
||||
if (hum_temp){
|
||||
hum_temp=false;
|
||||
temp = dht.getTemperature();
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
hum_temp=true;
|
||||
hum = dht.getHumidity();
|
||||
}
|
||||
|
@ -243,73 +300,63 @@ Serial.print("Init: DHT OK! Temp=");
|
|||
Serial.println(String(temp));
|
||||
|
||||
#if DEBUG
|
||||
writedisplaytext("","DEBUG",millis(),String(millis()),"",0);
|
||||
writedisplaytext("LoRa - APRS","","DEBUG",millis(),String(millis()),"",0);
|
||||
#endif
|
||||
//while(1) { if ( ss.available() ) Serial.write(ss.read());}
|
||||
#if !(FIXED_POSITION)
|
||||
// digitalWrite(GPSLED, HIGH);
|
||||
|
||||
if (tracker_mode != WX_FIXED) {
|
||||
while (ss.available() > 0) {
|
||||
gps.encode(ss.read());
|
||||
}
|
||||
#endif // #if !(FIXED_POSITION)
|
||||
|
||||
if (rf95.waitAvailableTimeout(100))
|
||||
{
|
||||
// Should be a reply message for us now
|
||||
if (rf95.recvAPRS(buf, &len))
|
||||
{
|
||||
// Serial.print("RX: ");
|
||||
// Serial.println((char*)buf);
|
||||
// Serial.print("RSSI: ");
|
||||
// Serial.println(rf95.lastRssi(), DEC);
|
||||
}
|
||||
|
||||
if (rf95.waitAvailableTimeout(100)) {
|
||||
if (rf95.recvAPRS(buf, &len)) {
|
||||
}
|
||||
}
|
||||
if (hum_temp)
|
||||
{
|
||||
writedisplaytext(" "+String(((lastTX+nextTX)-millis())/1000),"LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),0),"BAT: "+String(analogRead(35)*7.221/4096,2)+" HUM: "+String(hum),250);
|
||||
} else
|
||||
{
|
||||
writedisplaytext(" "+String(((lastTX+nextTX)-millis())/1000),"LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),0),"BAT: "+String(analogRead(35)*7.221/4096,2)+" TEMP: "+String(temp),250);
|
||||
writedisplaytext(" "+Tcall,"Time to TX: "+String(((lastTX+nextTX)-millis())/1000),"LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),1),"BAT: "+String(analogRead(35)*7.221/4096,1)+" HUM: "+String(hum,1),250);
|
||||
} else {
|
||||
writedisplaytext(" "+Tcall,"Time to TX: "+String(((lastTX+nextTX)-millis())/1000),"LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),1),"BAT: "+String(analogRead(35)*7.221/4096,1)+" TEMP: "+String(temp,1),250);
|
||||
}
|
||||
smartDelay(1000);
|
||||
|
||||
// digitalWrite(GPSLED, LOW);
|
||||
#if (FIXED_POSITION)
|
||||
// if (gps.location.isUpdated() || ( (lastTX+nextTX) <= millis() ) )
|
||||
if ( (lastTX+nextTX) <= millis() )
|
||||
#else
|
||||
if (gps.location.isValid() && ( (lastTX+nextTX) <= millis() ) )
|
||||
#endif
|
||||
{
|
||||
digitalWrite(TXLED, HIGH);
|
||||
batt_read();
|
||||
if (hum_temp)
|
||||
{
|
||||
writedisplaytext(" ((TX))","LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),0),"BAR: "+String(analogRead(35)*7.221/4096,2)+" HUM: "+String(hum),250);
|
||||
} else
|
||||
{
|
||||
writedisplaytext(" ((TX))","LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),0),"BAR: "+String(analogRead(35)*7.221/4096,2)+" TEMP: "+String(temp),250);
|
||||
}
|
||||
sendpacket();
|
||||
//writedisplaytext("","State:","Packet sent!","","",250);
|
||||
Serial.println("State: Packet sent!");
|
||||
digitalWrite(TXLED, LOW);
|
||||
} else {
|
||||
if ( (lastTX+nextTX*2) <= millis() )
|
||||
{
|
||||
if ( (lastTX+nextTX) <= millis() ) {
|
||||
if (tracker_mode != WX_FIXED) {
|
||||
if (gps.location.isValid()) {
|
||||
digitalWrite(TXLED, HIGH);
|
||||
batt_read();
|
||||
if (hum_temp) {
|
||||
writedisplaytext(" "+Tcall," ((TX))","LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),1),"BAT: "+String(analogRead(35)*7.221/4096,1)+" HUM: "+String(hum,1),250);
|
||||
} else {
|
||||
writedisplaytext(" "+Tcall," ((TX))","LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),1),"BAT: "+String(analogRead(35)*7.221/4096,1)+" TEMP: "+String(temp,1),250);
|
||||
}
|
||||
sendpacket();
|
||||
Serial.println("State: Packet sent!");
|
||||
digitalWrite(TXLED, LOW);
|
||||
} else {
|
||||
if ( (lastTX+nextTX*2) <= millis() ) {
|
||||
digitalWrite(TXLED, HIGH);
|
||||
batt_read();
|
||||
if (hum_temp) {
|
||||
writedisplaytext(" "+Tcall," ((TX))","LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),1),"BAR: "+String(analogRead(35)*7.221/4096,1)+" HUM: "+String(hum,1),250);
|
||||
} else {
|
||||
writedisplaytext(" "+Tcall," ((TX))","LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),1),"BAR: "+String(analogRead(35)*7.221/4096,1)+" TEMP: "+String(temp,1),250);
|
||||
}
|
||||
sendpacket();
|
||||
Serial.println("State: Packet sent!");
|
||||
digitalWrite(TXLED, LOW);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
digitalWrite(TXLED, HIGH);
|
||||
batt_read();
|
||||
if (hum_temp)
|
||||
{
|
||||
writedisplaytext(" ((TX))","LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),0),"BAR: "+String(analogRead(35)*7.221/4096,2)+" HUM: "+String(hum),250);
|
||||
} else
|
||||
{
|
||||
writedisplaytext(" ((TX))","LAT: "+String(gps.location.lat(),5),"LON: "+String(gps.location.lng(),5),"SPD: "+String(gps.speed.kmph(),1)+" CRS: "+String(gps.course.deg(),0),"BAR: "+String(analogRead(35)*7.221/4096,2)+" TEMP: "+String(temp),250);
|
||||
if (hum_temp) {
|
||||
writedisplaytext(" "+wxTcall," ((TX))","LAT: " + String(LATITUDE),"LON: " + String(LONGITUDE),"No GPS used","BAT: "+String(analogRead(35)*7.221/4096,1)+" HUM: "+String(hum,1),250);
|
||||
} else {
|
||||
writedisplaytext(" "+wxTcall," ((TX))","LAT: " + String(LATITUDE),"LON: " + String(LONGITUDE),"No GPS used","BAT: "+String(analogRead(35)*7.221/4096,1)+" TEMP: "+String(temp,1),250);
|
||||
}
|
||||
sendpacket();
|
||||
// writedisplaytext("","State:","Packet sent!","","",250);
|
||||
Serial.println("State: Packet sent!");
|
||||
digitalWrite(TXLED, LOW);
|
||||
}
|
||||
|
@ -317,13 +364,12 @@ smartDelay(1000);
|
|||
|
||||
smartDelay(1000);
|
||||
|
||||
#if !(FIXED_POSITION)
|
||||
if (millis() > 200000 && gps.charsProcessed() < 10)
|
||||
{
|
||||
writedisplaytext("","Warning","No GPS Signal!","","",1000);
|
||||
if (tracker_mode != WX_FIXED) {
|
||||
if (millis() > 200000 && gps.charsProcessed() < 10) {
|
||||
writedisplaytext(" "+Tcall,"","Warning","No GPS Signal!","","",1000);
|
||||
Serial.println("Warning: No GPS Signal!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -334,10 +380,10 @@ static void smartDelay(unsigned long ms)
|
|||
unsigned long start = millis();
|
||||
do
|
||||
{
|
||||
#if !(FIXED_POSITION)
|
||||
if (tracker_mode != WX_FIXED) {
|
||||
while (ss.available())
|
||||
gps.encode(ss.read());
|
||||
#endif
|
||||
}
|
||||
} while (millis() - start < ms);
|
||||
}
|
||||
|
||||
|
@ -352,7 +398,7 @@ void recalcGPS(){
|
|||
float Lat;
|
||||
float Lon;
|
||||
|
||||
#if !(FIXED_POSITION)
|
||||
if (tracker_mode != WX_FIXED) {
|
||||
Tlat=gps.location.lat();
|
||||
Tlon=gps.location.lng();
|
||||
Talt=gps.altitude.meters();
|
||||
|
@ -365,81 +411,19 @@ void recalcGPS(){
|
|||
if(Tlon < 0) { Tlon= -Tlon; }
|
||||
unsigned int Deg_Lon = Tlon;
|
||||
Lon = 100*(Deg_Lon) + (Tlon - Deg_Lon)*60;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !(SEND_WX)
|
||||
outString = "";
|
||||
outString = (Tcall);
|
||||
outString += ">APRS:!";
|
||||
#if (FIXED_POSITION)
|
||||
outString += LATITUDE;
|
||||
#else
|
||||
if(Tlat<10) {outString += "0"; }
|
||||
outString += String(Lat,2);
|
||||
outString += Ns;
|
||||
#endif
|
||||
outString += wxTable;
|
||||
#if (FIXED_POSITION)
|
||||
outString += LONGITUDE;
|
||||
#else
|
||||
if(Tlon<100) {outString += "0"; }
|
||||
if(Tlon<10) {outString += "0"; }
|
||||
outString += String(Lon,2);
|
||||
outString += Ew;
|
||||
#endif
|
||||
outString += sSymbol;
|
||||
outString += " /A=";
|
||||
outString += Talt;
|
||||
outString += "m Batt=";
|
||||
outString += String(BattVolts,2);
|
||||
outString += ("V");
|
||||
#else
|
||||
if ( !wx ) { // create standard position string
|
||||
#if !(FIXED_POSITION)
|
||||
outString = "";
|
||||
outString = (Tcall);
|
||||
outString += ">APRS:!";
|
||||
if(Tlat<10) {outString += "0"; }
|
||||
outString += String(Lat,2);
|
||||
outString += Ns;
|
||||
outString += sTable;
|
||||
if(Tlon<100) {outString += "0"; }
|
||||
if(Tlon<10) {outString += "0"; }
|
||||
outString += String(Lon,2);
|
||||
outString += Ew;
|
||||
outString += sSymbol;
|
||||
outString += " /A=";
|
||||
outString += Talt;
|
||||
outString += "m Batt=";
|
||||
outString += String(BattVolts,2);
|
||||
outString += ("V");
|
||||
wx = true;
|
||||
#endif
|
||||
} else { // create weather report string
|
||||
hum = dht.readHumidity();
|
||||
// hum = 88.67;
|
||||
// temp = 50.23;
|
||||
outString = "";
|
||||
|
||||
switch(tracker_mode) {
|
||||
case WX_FIXED:
|
||||
hum = dht.getHumidity();
|
||||
temp = dht.getTemperature();
|
||||
// temp = dht.readTemperature();
|
||||
outString = "";
|
||||
outString = (wxTcall);
|
||||
outString += ">APRS:!";
|
||||
#if (FIXED_POSITION)
|
||||
outString += LATITUDE;
|
||||
#else
|
||||
if(Tlat<10) {outString += "0"; }
|
||||
outString += String(Lat,2);
|
||||
outString += Ns;
|
||||
#endif
|
||||
outString += LATITUDE;
|
||||
outString += wxTable;
|
||||
#if (FIXED_POSITION)
|
||||
outString += LONGITUDE;
|
||||
#else
|
||||
if(Tlon<100) {outString += "0"; }
|
||||
if(Tlon<10) {outString += "0"; }
|
||||
outString += String(Lon,2);
|
||||
outString += Ew;
|
||||
#endif
|
||||
outString += LONGITUDE;
|
||||
outString += wxSymbol;
|
||||
outString += ".../...g...t";
|
||||
if (temp < 0) { // negative Werte erstellen
|
||||
|
@ -459,11 +443,114 @@ void recalcGPS(){
|
|||
helper.trim();
|
||||
outString += helper;
|
||||
outString += "b......DHT22";
|
||||
#if !(FIXED_POSITION)
|
||||
wx = false;
|
||||
#endif
|
||||
break;
|
||||
case WX_TRACKER:
|
||||
if (wx) {
|
||||
hum = dht.getHumidity();
|
||||
temp = dht.getTemperature();
|
||||
outString = (wxTcall);
|
||||
outString += ">APRS:!";
|
||||
if(Tlat<10) {outString += "0"; }
|
||||
outString += String(Lat,2);
|
||||
outString += Ns;
|
||||
outString += wxTable;
|
||||
if(Tlon<100) {outString += "0"; }
|
||||
if(Tlon<10) {outString += "0"; }
|
||||
outString += String(Lon,2);
|
||||
outString += Ew;
|
||||
outString += wxSymbol;
|
||||
outString += ".../...g...t";
|
||||
if (temp < 0) { // negative Werte erstellen
|
||||
outString += "-";
|
||||
if(temp>-10) {outString += "0"; }
|
||||
temp = abs(temp);
|
||||
} else { // positive Werte erstellen
|
||||
if(temp<100) {outString += "0"; }
|
||||
if(temp<10) {outString += "0"; }
|
||||
}
|
||||
helper = String(temp,0);
|
||||
helper.trim();
|
||||
outString += helper;
|
||||
outString += "r...p...P...h";
|
||||
if(hum<10) {outString += "0"; }
|
||||
helper = String(hum,0);
|
||||
helper.trim();
|
||||
outString += helper;
|
||||
outString += "b......DHT22";
|
||||
wx = !wx;
|
||||
} else {
|
||||
outString = (Tcall);
|
||||
outString += ">APRS:!";
|
||||
if(Tlat<10) {outString += "0"; }
|
||||
outString += String(Lat,2);
|
||||
outString += Ns;
|
||||
outString += sTable;
|
||||
if(Tlon<100) {outString += "0"; }
|
||||
if(Tlon<10) {outString += "0"; }
|
||||
outString += String(Lon,2);
|
||||
outString += Ew;
|
||||
outString += sSymbol;
|
||||
outString += " /A=";
|
||||
outString += Talt;
|
||||
outString += "m Batt=";
|
||||
outString += String(BattVolts,2);
|
||||
outString += ("V");
|
||||
wx = !wx;
|
||||
}
|
||||
break;
|
||||
case WX_MOVE:
|
||||
hum = dht.getHumidity();
|
||||
temp = dht.getTemperature();
|
||||
outString = (wxTcall);
|
||||
outString += ">APRS:!";
|
||||
if(Tlat<10) {outString += "0"; }
|
||||
outString += String(Lat,2);
|
||||
outString += Ns;
|
||||
outString += wxTable;
|
||||
if(Tlon<100) {outString += "0"; }
|
||||
if(Tlon<10) {outString += "0"; }
|
||||
outString += String(Lon,2);
|
||||
outString += Ew;
|
||||
outString += wxSymbol;
|
||||
outString += ".../...g...t";
|
||||
if (temp < 0) { // negative Werte erstellen
|
||||
outString += "-";
|
||||
if(temp>-10) {outString += "0"; }
|
||||
temp = abs(temp);
|
||||
} else { // positive Werte erstellen
|
||||
if(temp<100) {outString += "0"; }
|
||||
if(temp<10) {outString += "0"; }
|
||||
}
|
||||
helper = String(temp,0);
|
||||
helper.trim();
|
||||
outString += helper;
|
||||
outString += "r...p...P...h";
|
||||
if(hum<10) {outString += "0"; }
|
||||
helper = String(hum,0);
|
||||
helper.trim();
|
||||
outString += helper;
|
||||
outString += "b......DHT22";
|
||||
break;
|
||||
case TRACKER:
|
||||
default:
|
||||
outString = (Tcall);
|
||||
outString += ">APRS:!";
|
||||
if(Tlat<10) {outString += "0"; }
|
||||
outString += String(Lat,2);
|
||||
outString += Ns;
|
||||
outString += sTable;
|
||||
if(Tlon<100) {outString += "0"; }
|
||||
if(Tlon<10) {outString += "0"; }
|
||||
outString += String(Lon,2);
|
||||
outString += Ew;
|
||||
outString += sSymbol;
|
||||
outString += " /A=";
|
||||
outString += Talt;
|
||||
outString += "m Batt=";
|
||||
outString += String(BattVolts,2);
|
||||
outString += ("V");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -473,32 +560,30 @@ void sendpacket()
|
|||
batt_read();
|
||||
Outputstring = "";
|
||||
|
||||
#if !(FIXED_POSITION)
|
||||
if ( gps.location.isValid() || gps.location.isUpdated() )
|
||||
{
|
||||
// digitalWrite(GPSLED, HIGH);
|
||||
//New System
|
||||
//recalcEncodedGPS();
|
||||
#endif
|
||||
switch(tracker_mode) {
|
||||
case WX_FIXED:
|
||||
recalcGPS(); //
|
||||
// digitalWrite(PLED1, HIGH);
|
||||
Outputstring =outString;
|
||||
|
||||
loraSend(lora_TXStart, lora_TXEnd, 60, 255, 1, 10, TXdbmW, TXFREQ); //send the packet, data is in TXbuff from lora_TXStart to lora_TXEnd
|
||||
#if !(FIXED_POSITION)
|
||||
} else {
|
||||
Outputstring = (Tcall);
|
||||
Outputstring += " No GPS-Fix";
|
||||
Outputstring += " Batt=";
|
||||
Outputstring += String(BattVolts,2);
|
||||
Outputstring += ("V ");
|
||||
|
||||
loraSend(lora_TXStart, lora_TXEnd, 60, 255, 1, 10, 5, TXFREQ); //send the packet, data is in TXbuff from lora_TXStart to lora_TXEnd
|
||||
// digitalWrite(GPSLED, LOW);
|
||||
loraSend(lora_TXStart, lora_TXEnd, 60, 255, 1, 10, TXdbmW, TXFREQ); //send the packet, data is in TXbuff from lora_TXStart to lora_TXEnd
|
||||
break;
|
||||
case TRACKER:
|
||||
case WX_TRACKER:
|
||||
case WX_MOVE:
|
||||
default:
|
||||
if ( gps.location.isValid() || gps.location.isUpdated() ) {
|
||||
recalcGPS(); //
|
||||
Outputstring =outString;
|
||||
loraSend(lora_TXStart, lora_TXEnd, 60, 255, 1, 10, TXdbmW, TXFREQ); //send the packet, data is in TXbuff from lora_TXStart to lora_TXEnd
|
||||
} else {
|
||||
Outputstring = (Tcall);
|
||||
Outputstring += " No GPS-Fix";
|
||||
Outputstring += " Batt=";
|
||||
Outputstring += String(BattVolts,2);
|
||||
Outputstring += ("V ");
|
||||
loraSend(lora_TXStart, lora_TXEnd, 60, 255, 1, 10, 5, TXFREQ); //send the packet, data is in TXbuff from lora_TXStart to lora_TXEnd
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
// digitalWrite(PLED1, LOW);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -507,89 +592,48 @@ void loraSend(byte lora_LTXStart, byte lora_LTXEnd, byte lora_LTXPacketType, byt
|
|||
byte i;
|
||||
byte ltemp;
|
||||
|
||||
if (rf95.waitAvailableTimeout(100))
|
||||
{
|
||||
if (rf95.recvAPRS(buf, &len))
|
||||
{
|
||||
// Serial.print("RX before TX: ");
|
||||
// Serial.println((char*)buf);
|
||||
// Serial.print("RSSI: ");
|
||||
// Serial.println(rf95.lastRssi(), DEC);
|
||||
|
||||
}
|
||||
if (rf95.waitAvailableTimeout(100)) {
|
||||
if (rf95.recvAPRS(buf, &len)) {
|
||||
}
|
||||
}
|
||||
|
||||
// time of last TX
|
||||
lastTX = millis();
|
||||
// time of last TX
|
||||
lastTX = millis();
|
||||
|
||||
ltemp = Outputstring.length();
|
||||
for (i = 0; i <= ltemp; i++)
|
||||
{
|
||||
lora_TXBUFF[i] = Outputstring.charAt(i);
|
||||
}
|
||||
ltemp = Outputstring.length();
|
||||
for (i = 0; i <= ltemp; i++)
|
||||
{
|
||||
lora_TXBUFF[i] = Outputstring.charAt(i);
|
||||
}
|
||||
|
||||
i--;
|
||||
lora_TXEnd = i;
|
||||
lora_TXBUFF[i] ='\0';
|
||||
i--;
|
||||
lora_TXEnd = i;
|
||||
lora_TXBUFF[i] ='\0';
|
||||
|
||||
// digitalWrite(PLED1, HIGH); //LED on during packet
|
||||
|
||||
rf95.setModemConfig(BG_RF95::Bw125Cr45Sf4096);
|
||||
rf95.setFrequency(lora_FREQ);
|
||||
rf95.setTxPower(lora_LTXPower);
|
||||
|
||||
// Serial.print(Outputstring);
|
||||
// Serial.print(" len: ");
|
||||
// Serial.println(strlen(lora_TXBUFF) );
|
||||
|
||||
//digitalWrite(RX_en, LOW); //RX lo
|
||||
//digitalWrite(TX_en, HIGH); //TX HIGH
|
||||
//rf95.sendAPRS(lora_TXBUFF, sizeof(lora_TXBUFF));
|
||||
rf95.sendAPRS(lora_TXBUFF, Outputstring.length());
|
||||
|
||||
// rf95.sendAPRS(lora_TXBUFF, lora_TXBUFF.length());
|
||||
rf95.waitPacketSent();
|
||||
|
||||
//digitalWrite(TX_en, LOW); //TX lo
|
||||
//digitalWrite(RX_en,HIGH); //RX HIGH
|
||||
|
||||
|
||||
|
||||
|
||||
// digitalWrite(PLED1, LOW);
|
||||
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
void batt_read()
|
||||
{
|
||||
float BattRead = analogRead(35)*7.221;
|
||||
// Serial.println("Batt: "+String(BattRead));
|
||||
//int BattRead = adc1_get_raw(ADC1_CHANNEL_7);
|
||||
// delay(250);
|
||||
//lora_TXBUFF[1] = (BattRead / 256); //MSB of battery volts
|
||||
//lora_TXBUFF[0] = (BattRead - (lora_TXBUFF[1] * 256)); //LSB of battery volts
|
||||
|
||||
BattVolts = (BattRead / 4096);
|
||||
// BattVolts = BattRead;
|
||||
// writedisplaytext(String(BattVolts,2), "", "", "", "", 0);
|
||||
|
||||
//Serial.print("lora_TXBUFF[0] ");
|
||||
//Serial.println(lora_TXBUFF[0]);
|
||||
//Serial.print("lora_TXBUFF[1] ");
|
||||
//Serial.println(lora_TXBUFF[1]);
|
||||
//Serial.println("Battery ");
|
||||
//Serial.print(BattVolts, 2);
|
||||
//Serial.println("V");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
void writedisplaytext(String Line1, String Line2, String Line3, String Line4, String Line5, int warten)
|
||||
void writedisplaytext(String HeaderTxt, String Line1, String Line2, String Line3, String Line4, String Line5, int warten)
|
||||
{
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(2);
|
||||
display.setCursor(0,0);
|
||||
display.println(" LoRa-APRS");
|
||||
display.println(HeaderTxt);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(0,16);
|
||||
display.println(Line1);
|
||||
|
|
|
@ -28,19 +28,11 @@ String sSymbol=">"; //symbol code CAR
|
|||
// String sSymbol="b"; //symbol code BICYCLE
|
||||
// String sSymbol="<"; //symbol code MOTORCYCLE
|
||||
|
||||
// SEND_WX - if true the tracker sends WX reports - needs DHT22 connected at Pin 10
|
||||
// when FIXED_POSITION is false then it sends alternating normal position packets and weather report packets
|
||||
#define SEND_WX false
|
||||
|
||||
// Your symbol table and symbol for weather reports
|
||||
String wxTable="/"; //Primer
|
||||
String wxSymbol="_"; //Symbol Code Weather Station
|
||||
// String wxSymbol="W"; //Symbol Code Weather Station/
|
||||
|
||||
#define FIXED_POSITION false
|
||||
// set to true if you want to use fixed position (position defined below) instead, or to false if you want to use GPS data
|
||||
// also stops sending normal position reports when sending weather reports is active (SEND_WX true)
|
||||
|
||||
#define LATITUDE "4813.62N" // please in APRS notation DDMM.mmN or DDMM.mmS used for FIXED_POSITION
|
||||
#define LONGITUDE "01539.85E" // please in APRS notation DDDMM.mmE or DDDMM.mmW used for FIXED_POSITION
|
||||
// ^^^^^LATITUDE and LONGITUDE only used when FIXED_POSITION is true
|
||||
|
|
Loading…
Reference in New Issue