communicate via json, display rssi and from, dynamic min and max speed via json
This commit is contained in:
64
src/main.cpp
64
src/main.cpp
@@ -2,13 +2,14 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <U8g2lib.h>
|
#include <U8g2lib.h>
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
#ifdef DEVICE_WINDE
|
#ifdef DEVICE_WINDE
|
||||||
#include <tacho.h>
|
#include <tacho.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEVICE_SAILPLANE
|
#ifdef DEVICE_SAILPLANE
|
||||||
#include <airspeed.h>
|
#include <airspeed.h>
|
||||||
|
JsonDocument sailplane_data;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SX1262 radio = new Module(LORA_NSS, LORA_DIO1, LORA_NRST, LORA_BUSY);
|
SX1262 radio = new Module(LORA_NSS, LORA_DIO1, LORA_NRST, LORA_BUSY);
|
||||||
@@ -89,6 +90,37 @@ void setup()
|
|||||||
u8g2.sendBuffer();
|
u8g2.sendBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_rssi(int Rssi){
|
||||||
|
u8g2.drawFrame(102,8,4,3);
|
||||||
|
u8g2.drawFrame(107,6,4,5);
|
||||||
|
u8g2.drawFrame(112,4,4,7);
|
||||||
|
u8g2.drawFrame(117,2,4,9);
|
||||||
|
u8g2.drawFrame(122,0,4,11);
|
||||||
|
|
||||||
|
if ((Rssi > -120) && Rssi < 0 )
|
||||||
|
{
|
||||||
|
u8g2.drawBox(102,8,4,3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((Rssi > -100) && Rssi < 0 )
|
||||||
|
{
|
||||||
|
u8g2.drawBox(107,6,4,5);
|
||||||
|
}
|
||||||
|
if ((Rssi > -85) && Rssi < 0 )
|
||||||
|
{
|
||||||
|
u8g2.drawBox(112,4,4,7);
|
||||||
|
}
|
||||||
|
if ((Rssi > -70) && Rssi < 0 )
|
||||||
|
{
|
||||||
|
u8g2.drawBox(117,2,4,9);
|
||||||
|
}
|
||||||
|
if ((Rssi > -55) && Rssi < 0 )
|
||||||
|
{
|
||||||
|
u8g2.drawBox(122,0,4,11);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
#ifdef DEVICE_SAILPLANE
|
#ifdef DEVICE_SAILPLANE
|
||||||
@@ -103,7 +135,13 @@ void loop()
|
|||||||
u8g2.sendBuffer();
|
u8g2.sendBuffer();
|
||||||
if (vel_kmh > 30)
|
if (vel_kmh > 30)
|
||||||
{
|
{
|
||||||
String data = String(vel_kmh);
|
sailplane_data["from"]= "D-1234";
|
||||||
|
sailplane_data["telemetry"]["speed"]=vel_kmh;
|
||||||
|
sailplane_data["telemetry"]["min"]=70;
|
||||||
|
sailplane_data["telemetry"]["max"]=150;
|
||||||
|
String data;
|
||||||
|
serializeJson(sailplane_data,data);
|
||||||
|
//String data = String(vel_kmh);
|
||||||
int state = radio.transmit(data);
|
int state = radio.transmit(data);
|
||||||
if (state == RADIOLIB_ERR_NONE)
|
if (state == RADIOLIB_ERR_NONE)
|
||||||
{
|
{
|
||||||
@@ -157,6 +195,8 @@ void loop()
|
|||||||
// you can read received data as an Arduino String
|
// you can read received data as an Arduino String
|
||||||
String str;
|
String str;
|
||||||
int state = radio.readData(str);
|
int state = radio.readData(str);
|
||||||
|
JsonDocument received;
|
||||||
|
deserializeJson(received,str);
|
||||||
|
|
||||||
// you can also read received data as byte array
|
// you can also read received data as byte array
|
||||||
/*
|
/*
|
||||||
@@ -167,15 +207,27 @@ void loop()
|
|||||||
|
|
||||||
if (state == RADIOLIB_ERR_NONE)
|
if (state == RADIOLIB_ERR_NONE)
|
||||||
{
|
{
|
||||||
|
String data_from=received["from"];
|
||||||
|
int data_speed=received["telemetry"]["speed"];
|
||||||
|
int data_min=received["telemetry"]["min"];
|
||||||
|
int data_max=received["telemetry"]["max"];
|
||||||
// packet was successfully received
|
// packet was successfully received
|
||||||
u8g2.clearBuffer();
|
u8g2.clearBuffer();
|
||||||
u8g2.setFont(u8g2_font_logisoso42_tr);
|
u8g2.setFont(u8g2_font_ncenB10_tr);
|
||||||
u8g2.setCursor(0, 60);
|
u8g2.setCursor(0, 10);
|
||||||
u8g2.print(str);
|
u8g2.print(data_from);
|
||||||
|
u8g2.setCursor(0, 64);
|
||||||
|
u8g2.print(data_min);
|
||||||
|
u8g2.setCursor(64, 64);
|
||||||
|
u8g2.print(data_max);
|
||||||
|
u8g2.setFont(u8g2_font_logisoso32_tr);
|
||||||
|
u8g2.setCursor(0, 50);
|
||||||
|
u8g2.print(data_speed);
|
||||||
|
draw_rssi(radio.getRSSI());
|
||||||
u8g2.sendBuffer();
|
u8g2.sendBuffer();
|
||||||
Serial.println(str);
|
Serial.println(str);
|
||||||
int speed = str.toInt();
|
int speed = str.toInt();
|
||||||
set_tacho(speed, 70, 150);
|
set_tacho(data_speed, data_min, data_max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user