Dokumentation um Webinterface, Einstellungen und OTA-Update erweitert
This commit is contained in:
1 parent
1014df8ec7
commit
0d2ff764ea
13 files changed
+531
-85
No files matched your search
+84
-41
@@ -3,23 +3,25 @@
|
||||
#include <U8g2lib.h>
|
||||
#include <RadioLib.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <webinterface.h>
|
||||
#ifdef DEVICE_WINDE
|
||||
#include <tacho.h>
|
||||
#endif
|
||||
|
||||
TelemetrySettings telemetry_settings;
|
||||
|
||||
#ifdef DEVICE_SAILPLANE
|
||||
#include <airspeed.h>
|
||||
unsigned long previousMillisSend = 0;
|
||||
const long send_interval = 1000;
|
||||
unsigned long previousMillissendtimer = 0;
|
||||
const long sendtimer_max = 90000;
|
||||
bool send_data = false;
|
||||
bool is_airborn = false;
|
||||
int lowspeedtimer = 0;
|
||||
int lowspeedtimermax = 90000;
|
||||
unsigned long lowspeedtimer = 0;
|
||||
bool sensors_ready = false;
|
||||
#endif
|
||||
|
||||
SX1262 radio = new Module(LORA_NSS, LORA_DIO1, LORA_NRST, LORA_BUSY);
|
||||
bool radio_ready = false;
|
||||
#ifdef DEVICE_WINDE
|
||||
volatile bool receivedFlag = false;
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
@@ -50,50 +52,53 @@ void setup()
|
||||
/* Serial to display data */
|
||||
Serial.begin(115200);
|
||||
Serial.println("start");
|
||||
if (!webinterface_begin(telemetry_settings))
|
||||
Serial.println("Webinterface konnte nicht gestartet werden");
|
||||
int state = radio.begin(LORA_FREQ);
|
||||
if (state == RADIOLIB_ERR_NONE)
|
||||
{
|
||||
radio_ready = true;
|
||||
Serial.println(F("success!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true)
|
||||
{
|
||||
delay(10);
|
||||
}
|
||||
Serial.println(F("Webinterface bleibt verfuegbar"));
|
||||
}
|
||||
u8g2.begin();
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_ncenB14_tr);
|
||||
#ifdef DEVICE_SAILPLANE
|
||||
u8g2.drawStr(0, 20, "Start Plane");
|
||||
init_2ndi2c();
|
||||
init_airspeed_sensor();
|
||||
init_pressure_sensor();
|
||||
sensors_ready = init_2ndi2c() && init_airspeed_sensor() && init_pressure_sensor();
|
||||
if (!sensors_ready)
|
||||
{
|
||||
u8g2.drawStr(0, 40, "Sensor error");
|
||||
}
|
||||
#endif
|
||||
#ifdef DEVICE_WINDE
|
||||
u8g2.drawStr(0, 20, "Start Winde");
|
||||
init_servo();
|
||||
init_pixel();
|
||||
init_servo();
|
||||
set_tacho(0, telemetry_settings.min_speed, telemetry_settings.max_speed);
|
||||
|
||||
radio.setPacketReceivedAction(setFlag);
|
||||
|
||||
// start listening for LoRa packets
|
||||
|
||||
state = radio.startReceive();
|
||||
if (state == RADIOLIB_ERR_NONE)
|
||||
if (radio_ready)
|
||||
{
|
||||
Serial.println(F("success!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true)
|
||||
state = radio.startReceive();
|
||||
if (state == RADIOLIB_ERR_NONE)
|
||||
{
|
||||
delay(10);
|
||||
Serial.println(F("success!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
radio_ready = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -105,10 +110,9 @@ String nmea_checksum(String str)
|
||||
byte cs = 0;
|
||||
for (unsigned int n = 1; n < str.length(); n++)
|
||||
{
|
||||
if (str[n] != '$' || str[n] != '!' || str[n] != '*')
|
||||
{
|
||||
cs ^= str[n];
|
||||
}
|
||||
if (str[n] == '*')
|
||||
break;
|
||||
cs ^= str[n];
|
||||
}
|
||||
|
||||
if (cs < 0x10)
|
||||
@@ -150,6 +154,9 @@ void draw_rssi(int Rssi){
|
||||
|
||||
void send_lora(String data)
|
||||
{
|
||||
if (!radio_ready)
|
||||
return;
|
||||
|
||||
int state = radio.transmit(data);
|
||||
if (state == RADIOLIB_ERR_NONE)
|
||||
{
|
||||
@@ -158,7 +165,7 @@ void send_lora(String data)
|
||||
|
||||
// print measured data rate
|
||||
Serial.print(F("[SX1262] Datarate:\t"));
|
||||
Serial.print(radio.getDataRate());
|
||||
//Serial.print(radio.getDataRate());
|
||||
Serial.println(F(" bps"));
|
||||
}
|
||||
else if (state == RADIOLIB_ERR_PACKET_TOO_LONG)
|
||||
@@ -184,7 +191,7 @@ void send_speed(int vel_kmh)
|
||||
String data;
|
||||
// serializeJson(sailplane_data, data);
|
||||
// sprintf(data,"$PWTLS,%s,%u,%u,%u","D-1234",vel_kmh,70,140);
|
||||
data = "$PWTLS,D1234," + String(vel_kmh) + ",70,140";
|
||||
data = "$PWTLS," + telemetry_settings.callsign + "," + String(vel_kmh) + "," + String(telemetry_settings.min_speed) + "," + String(telemetry_settings.max_speed);
|
||||
data += nmea_checksum(data);
|
||||
Serial.println(data);
|
||||
send_lora(data);
|
||||
@@ -194,7 +201,7 @@ void send_airborn()
|
||||
{
|
||||
String data;
|
||||
// serializeJson(sailplane_data, data);
|
||||
data = "$PWTLA,D1234,1";
|
||||
data = "$PWTLA," + telemetry_settings.callsign + ",1";
|
||||
data += nmea_checksum(data);
|
||||
Serial.println(data);
|
||||
send_lora(data);
|
||||
@@ -215,6 +222,8 @@ String getSplitValue(String data, char separator, int index)
|
||||
}
|
||||
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
|
||||
}
|
||||
#ifdef DEVICE_WINDE
|
||||
|
||||
void decode_start(String data)
|
||||
{
|
||||
data_from = getSplitValue(data, ',', 1);
|
||||
@@ -229,28 +238,59 @@ void decode_airborn(String data)
|
||||
data_min = 0;
|
||||
data_max = 0;
|
||||
}
|
||||
void decode_msg(String data)
|
||||
|
||||
bool valid_nmea(String data)
|
||||
{
|
||||
int checksum_start = data.indexOf('*');
|
||||
if (checksum_start <= 1 || checksum_start + 2 >= data.length())
|
||||
return false;
|
||||
|
||||
byte checksum = 0;
|
||||
for (int i = 1; i < checksum_start; ++i)
|
||||
checksum ^= data[i];
|
||||
|
||||
String received_checksum = data.substring(checksum_start + 1, checksum_start + 3);
|
||||
received_checksum.toUpperCase();
|
||||
char expected_checksum[3];
|
||||
snprintf(expected_checksum, sizeof(expected_checksum), "%02X", checksum);
|
||||
return received_checksum == expected_checksum;
|
||||
}
|
||||
|
||||
bool decode_msg(String data)
|
||||
{
|
||||
String pos1 = getSplitValue(data, ',', 0);
|
||||
if (pos1 == "$PWTLS")
|
||||
{
|
||||
if (getSplitValue(data, ',', 4).length() == 0)
|
||||
return false;
|
||||
decode_start(data);
|
||||
return true;
|
||||
}
|
||||
else if (pos1 == "$PWTLA")
|
||||
{
|
||||
decode_airborn(data);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Nachricht nicht erkannt");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
void loop()
|
||||
{
|
||||
webinterface_handle();
|
||||
#ifdef DEVICE_SAILPLANE
|
||||
if (!sensors_ready)
|
||||
{
|
||||
delay(1000);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillisSend >= send_interval)
|
||||
unsigned long active_time_ms = telemetry_settings.active_time_seconds * 1000UL;
|
||||
if (currentMillis - previousMillisSend >= TELEMETRY_SEND_INTERVAL_MS)
|
||||
{
|
||||
previousMillisSend = currentMillis;
|
||||
/* Read the sensor */
|
||||
@@ -264,13 +304,13 @@ void loop()
|
||||
|
||||
if (send_data == false)
|
||||
{
|
||||
if (vel_kmh < 30)
|
||||
if (vel_kmh < telemetry_settings.min_speed)
|
||||
{
|
||||
lowspeedtimer++;
|
||||
if (lowspeedtimer >= lowspeedtimermax)
|
||||
lowspeedtimer += TELEMETRY_SEND_INTERVAL_MS;
|
||||
if (lowspeedtimer >= active_time_ms)
|
||||
{
|
||||
is_airborn = false;
|
||||
lowspeedtimer = lowspeedtimermax;
|
||||
lowspeedtimer = active_time_ms;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -289,7 +329,7 @@ void loop()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentMillis - previousMillissendtimer < sendtimer_max)
|
||||
if (currentMillis - previousMillissendtimer < active_time_ms)
|
||||
{
|
||||
send_speed(vel_kmh);
|
||||
}
|
||||
@@ -308,7 +348,7 @@ void loop()
|
||||
Serial.println(vel_kmh);
|
||||
Serial.print(pres.pres_pa(), 6);
|
||||
Serial.print("IAS (m/s): ");
|
||||
Serial.println(ias);
|
||||
Serial.println(get_airspeed());
|
||||
Serial.println(vel_kmh);
|
||||
Serial.print("\t");
|
||||
Serial.print(pres.die_temp_c(), 6);
|
||||
@@ -318,7 +358,7 @@ void loop()
|
||||
|
||||
#endif
|
||||
#ifdef DEVICE_WINDE
|
||||
if (receivedFlag)
|
||||
if (radio_ready && receivedFlag)
|
||||
{
|
||||
// reset flag
|
||||
receivedFlag = false;
|
||||
@@ -329,7 +369,11 @@ void loop()
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE)
|
||||
{
|
||||
decode_msg(str);
|
||||
if (!valid_nmea(str) || !decode_msg(str))
|
||||
{
|
||||
Serial.println("Ungueltige Telemetrie-Nachricht");
|
||||
return;
|
||||
}
|
||||
// packet was successfully received
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_ncenB10_tr);
|
||||
@@ -345,7 +389,6 @@ void loop()
|
||||
draw_rssi(radio.getRSSI());
|
||||
u8g2.sendBuffer();
|
||||
Serial.println(str);
|
||||
int speed = str.toInt();
|
||||
set_tacho(data_speed, data_min, data_max);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user