test
This commit is contained in:
@@ -13,6 +13,12 @@
|
|||||||
#define DownlinkPacketType_Ping 1
|
#define DownlinkPacketType_Ping 1
|
||||||
#define DownlinkPacketType_ACK 255
|
#define DownlinkPacketType_ACK 255
|
||||||
|
|
||||||
|
#define BME680_PRESENT_BIT (1 << 0)
|
||||||
|
#define CCS811_PRESENT_BIT (1 << 1)
|
||||||
|
#define MPU9250_PRESENT_BIT (1 << 2)
|
||||||
|
#define INA260_PRESENT_BIT (1 << 3)
|
||||||
|
#define MCP23018_PRESENT_BIT (1 << 4)
|
||||||
|
|
||||||
typedef struct __attribute__((packed))
|
typedef struct __attribute__((packed))
|
||||||
{
|
{
|
||||||
char syncPhrase[10];
|
char syncPhrase[10];
|
||||||
@@ -91,6 +97,8 @@ typedef struct __attribute__((packed))
|
|||||||
int16_t currentServoB;
|
int16_t currentServoB;
|
||||||
int16_t targetServoB;
|
int16_t targetServoB;
|
||||||
|
|
||||||
|
uint8_t presentDevices;
|
||||||
|
|
||||||
uint8_t telemetryIndex;
|
uint8_t telemetryIndex;
|
||||||
|
|
||||||
} TelemetryPacket;
|
} TelemetryPacket;
|
||||||
|
143
main/radio.c
143
main/radio.c
@@ -8,7 +8,6 @@
|
|||||||
#include "packets.h"
|
#include "packets.h"
|
||||||
#include "esp_rom_crc.h"
|
#include "esp_rom_crc.h"
|
||||||
|
|
||||||
|
|
||||||
#define TAG "LoRaGS"
|
#define TAG "LoRaGS"
|
||||||
|
|
||||||
uint32_t uplinkPacketIndex = 0;
|
uint32_t uplinkPacketIndex = 0;
|
||||||
@@ -70,58 +69,79 @@ void printTelemetryPacket(const TelemetryPacket *packet)
|
|||||||
|
|
||||||
temp_f = (packet->accelerometer_temperature / 333.87) + 21.0; // Temperature in °C
|
temp_f = (packet->accelerometer_temperature / 333.87) + 21.0; // Temperature in °C
|
||||||
|
|
||||||
// MPU Data
|
if (packet->presentDevices & MPU9250_PRESENT_BIT)
|
||||||
ESP_LOGI(TAG, " MPU:");
|
{
|
||||||
ESP_LOGI(TAG, " Acceleration [X: %d, Y: %d, Z: %d]", packet->accelerationX, packet->accelerationY, packet->accelerationZ);
|
// MPU Data
|
||||||
ESP_LOGI(TAG, " Gyroscope [X: %d, Y: %d, Z: %d]", packet->gyroX, packet->gyroY, packet->gyroZ);
|
ESP_LOGI(TAG, " MPU:");
|
||||||
ESP_LOGI(TAG, " Magnetometer [X: %d, Y: %d, Z: %d]", packet->magnetX, packet->magnetY, packet->magnetZ);
|
ESP_LOGI(TAG, " Acceleration [X: %d, Y: %d, Z: %d]", packet->accelerationX, packet->accelerationY, packet->accelerationZ);
|
||||||
ESP_LOGI(TAG, " Accelerometer Temp: %d", packet->accelerometer_temperature);
|
ESP_LOGI(TAG, " Gyroscope [X: %d, Y: %d, Z: %d]", packet->gyroX, packet->gyroY, packet->gyroZ);
|
||||||
|
ESP_LOGI(TAG, " Magnetometer [X: %d, Y: %d, Z: %d]", packet->magnetX, packet->magnetY, packet->magnetZ);
|
||||||
|
ESP_LOGI(TAG, " Accelerometer Temp: %d", packet->accelerometer_temperature);
|
||||||
|
|
||||||
ESP_LOGI(TAG, " MPU (Processed Readings):");
|
ESP_LOGI(TAG, " MPU (Processed Readings):");
|
||||||
|
|
||||||
ESP_LOGI(TAG, " Acceleration [X: %.3f g, Y: %.3f g, Z: %.3f g]", accel_f[0], accel_f[1], accel_f[2]);
|
ESP_LOGI(TAG, " Acceleration [X: %.3f g, Y: %.3f g, Z: %.3f g]", accel_f[0], accel_f[1], accel_f[2]);
|
||||||
ESP_LOGI(TAG, " Gyroscope [X: %.3f deg/s, Y: %.3f deg/s, Z: %.3f deg/s]", gyro_f[0], gyro_f[1], gyro_f[2]);
|
ESP_LOGI(TAG, " Gyroscope [X: %.3f deg/s, Y: %.3f deg/s, Z: %.3f deg/s]", gyro_f[0], gyro_f[1], gyro_f[2]);
|
||||||
ESP_LOGI(TAG, " Magnetometer [X: %.3f uT, Y: %.3f uT, Z: %.3f uT]", magnet_f[0], magnet_f[1], magnet_f[2]);
|
ESP_LOGI(TAG, " Magnetometer [X: %.3f uT, Y: %.3f uT, Z: %.3f uT]", magnet_f[0], magnet_f[1], magnet_f[2]);
|
||||||
ESP_LOGI(TAG, " Accelerometer Temp: %f °C", temp_f);
|
ESP_LOGI(TAG, " Accelerometer Temp: %f °C", temp_f);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, " MPU9250 not plugged in");
|
||||||
|
}
|
||||||
|
|
||||||
// CCS Data
|
if (packet->presentDevices & CCS811_PRESENT_BIT)
|
||||||
ESP_LOGI(TAG, " CCS:");
|
{
|
||||||
ESP_LOGI(TAG, " eCO2: %u ppm", packet->eCO2);
|
// CCS Data
|
||||||
ESP_LOGI(TAG, " TVOC: %u ppb", packet->tvoc);
|
ESP_LOGI(TAG, " CCS:");
|
||||||
ESP_LOGI(TAG, " Current CCS: %u", packet->currentCCS);
|
ESP_LOGI(TAG, " eCO2: %u ppm", packet->eCO2);
|
||||||
ESP_LOGI(TAG, " Raw CCS Data: %u", packet->rawCCSData);
|
ESP_LOGI(TAG, " TVOC: %u ppb", packet->tvoc);
|
||||||
|
ESP_LOGI(TAG, " Current CCS: %u", packet->currentCCS);
|
||||||
|
ESP_LOGI(TAG, " Raw CCS Data: %u", packet->rawCCSData);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, " CCS811 not plugged in");
|
||||||
|
}
|
||||||
|
|
||||||
float miliVolts = packet->volts * 1.25;
|
if (packet->presentDevices & INA260_PRESENT_BIT)
|
||||||
float miliAmps = packet->current * 1.25;
|
{
|
||||||
float power = packet->power * 10;
|
float miliVolts = packet->volts * 1.25;
|
||||||
|
float miliAmps = packet->current * 1.25;
|
||||||
|
float power = packet->power * 10;
|
||||||
|
|
||||||
// INA Data
|
// INA Data
|
||||||
ESP_LOGI(TAG, " INA:");
|
ESP_LOGI(TAG, " INA:");
|
||||||
ESP_LOGI(TAG, " Voltage: %f mV", miliVolts);
|
ESP_LOGI(TAG, " Voltage: %f mV", miliVolts);
|
||||||
ESP_LOGI(TAG, " Current: %f mA", miliAmps);
|
ESP_LOGI(TAG, " Current: %f mA", miliAmps);
|
||||||
ESP_LOGI(TAG, " Power: %f mW", power);
|
ESP_LOGI(TAG, " Power: %f mW", power);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGE(TAG, " INA260 not plugged in");
|
||||||
|
}
|
||||||
|
if (packet->presentDevices & BME680_PRESENT_BIT)
|
||||||
|
{
|
||||||
|
|
||||||
// BME Data
|
// BME Data
|
||||||
ESP_LOGI(TAG, " BME:");
|
ESP_LOGI(TAG, " BME:");
|
||||||
ESP_LOGI(TAG, " Temperature: %.2f °C", packet->temperature / 100.0f);
|
ESP_LOGI(TAG, " Temperature: %.2f °C", packet->temperature / 100.0f);
|
||||||
ESP_LOGI(TAG, " Humidity: %.2f %%", packet->humidity / 100.0f);
|
ESP_LOGI(TAG, " Humidity: %.2f %%", packet->humidity / 100.0f);
|
||||||
ESP_LOGI(TAG, " Pressure: %.2f hPa", packet->pressure / 100.0f);
|
ESP_LOGI(TAG, " Pressure: %.2f hPa", packet->pressure / 100.0f);
|
||||||
ESP_LOGI(TAG, " Gas Resistance: %u Ohms", packet->gas);
|
ESP_LOGI(TAG, " Gas Resistance: %u Ohms", packet->gas);
|
||||||
ESP_LOGI(TAG, " Gas Valid: %s", packet->gas_valid ? "Yes" : "No");
|
ESP_LOGI(TAG, " Gas Valid: %s", packet->gas_valid ? "Yes" : "No");
|
||||||
ESP_LOGI(TAG, " Heater Stable: %s", packet->heater_stable ? "Yes" : "No");
|
ESP_LOGI(TAG, " Heater Stable: %s", packet->heater_stable ? "Yes" : "No");
|
||||||
ESP_LOGI(TAG, " Gas Range: %u", packet->gas_range);
|
ESP_LOGI(TAG, " Gas Range: %u", packet->gas_range);
|
||||||
ESP_LOGI(TAG, " Gas Index: %u", packet->gas_index);
|
ESP_LOGI(TAG, " Gas Index: %u", packet->gas_index);
|
||||||
|
|
||||||
// BME Processed Data
|
// BME Processed Data
|
||||||
ESP_LOGI(TAG, " BME (Processed / Compensated Readings):");
|
ESP_LOGI(TAG, " BME (Processed / Compensated Readings):");
|
||||||
ESP_LOGI(TAG, " Air Temperature: %.2f °C", packet->air_temperature);
|
ESP_LOGI(TAG, " Air Temperature: %.2f °C", packet->air_temperature);
|
||||||
ESP_LOGI(TAG, " Relative Humidity: %.2f %%", packet->relative_humidity);
|
ESP_LOGI(TAG, " Relative Humidity: %.2f %%", packet->relative_humidity);
|
||||||
ESP_LOGI(TAG, " Barometric Pressure: %.2f hPa", packet->barometric_pressure);
|
ESP_LOGI(TAG, " Barometric Pressure: %.2f hPa", packet->barometric_pressure);
|
||||||
ESP_LOGI(TAG, " Gas Resistance: %.2f Ohms", packet->gas_resistance);
|
ESP_LOGI(TAG, " Gas Resistance: %.2f Ohms", packet->gas_resistance);
|
||||||
ESP_LOGI(TAG, " IAQ Score: %u", packet->iaq_score);
|
ESP_LOGI(TAG, " IAQ Score: %u", packet->iaq_score);
|
||||||
ESP_LOGI(TAG, " Temperature Score: %.2f", packet->temperature_score);
|
ESP_LOGI(TAG, " Temperature Score: %.2f", packet->temperature_score);
|
||||||
ESP_LOGI(TAG, " Humidity Score: %.2f", packet->humidity_score);
|
ESP_LOGI(TAG, " Humidity Score: %.2f", packet->humidity_score);
|
||||||
ESP_LOGI(TAG, " Gas Score: %.2f", packet->gas_score);
|
ESP_LOGI(TAG, " Gas Score: %.2f", packet->gas_score);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, " BME680 not plugged in");
|
||||||
|
}
|
||||||
|
|
||||||
// GPS Data
|
// GPS Data
|
||||||
ESP_LOGI(TAG, " GPS:");
|
ESP_LOGI(TAG, " GPS:");
|
||||||
@@ -139,19 +159,23 @@ void printTelemetryPacket(const TelemetryPacket *packet)
|
|||||||
ESP_LOGI(TAG, " Predicted Longitude: %.4f°", packet->predicted_longitude_centi_degrees / 10000.0f);
|
ESP_LOGI(TAG, " Predicted Longitude: %.4f°", packet->predicted_longitude_centi_degrees / 10000.0f);
|
||||||
ESP_LOGI(TAG, " Predicted Altitude: %.2f m", packet->predicted_altitude_centi_meters / 100.0f);
|
ESP_LOGI(TAG, " Predicted Altitude: %.2f m", packet->predicted_altitude_centi_meters / 100.0f);
|
||||||
|
|
||||||
// ADC Data
|
if (packet->presentDevices & MCP23018_PRESENT_BIT)
|
||||||
ESP_LOGI(TAG, " ADC Sensors:");
|
{
|
||||||
ESP_LOGI(TAG, " NH3: %d", packet->NH3);
|
// ADC Data
|
||||||
ESP_LOGI(TAG, " CO: %d", packet->CO);
|
ESP_LOGI(TAG, " ADC Sensors:");
|
||||||
ESP_LOGI(TAG, " NO2: %d", packet->NO2);
|
ESP_LOGI(TAG, " NH3: %d", packet->NH3);
|
||||||
ESP_LOGI(TAG, " UVC: %d", packet->UVC);
|
ESP_LOGI(TAG, " CO: %d", packet->CO);
|
||||||
|
ESP_LOGI(TAG, " NO2: %d", packet->NO2);
|
||||||
|
ESP_LOGI(TAG, " UVC: %d", packet->UVC);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, " IO Expander not plugged in");
|
||||||
|
}
|
||||||
|
|
||||||
// Servo Data
|
// Servo Data
|
||||||
ESP_LOGI(TAG, " Servos:");
|
ESP_LOGI(TAG, " Servos:");
|
||||||
ESP_LOGI(TAG, " Servo A: Current = %d, Target = %d", packet->currentServoA, packet->targetServoA);
|
ESP_LOGI(TAG, " Servo A: Current = %d, Target = %d", packet->currentServoA, packet->targetServoA);
|
||||||
ESP_LOGI(TAG, " Servo B: Current = %d, Target = %d", packet->currentServoB, packet->targetServoB);
|
ESP_LOGI(TAG, " Servo B: Current = %d, Target = %d", packet->currentServoB, packet->targetServoB);
|
||||||
ESP_LOGI(TAG, " TelemetryIndex: %d", packet->telemetryIndex);
|
ESP_LOGI(TAG, " TelemetryIndex: %d", packet->telemetryIndex);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
||||||
@@ -179,7 +203,8 @@ void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
|||||||
|
|
||||||
uint32_t crcCheck = esp_rom_crc32_le(0, payload, payloadSize);
|
uint32_t crcCheck = esp_rom_crc32_le(0, payload, payloadSize);
|
||||||
|
|
||||||
if (crcCheck != down.CRCCheck) {
|
if (crcCheck != down.CRCCheck)
|
||||||
|
{
|
||||||
ESP_LOGE(TAG, "Received BAD CRC for packet %d, crc is %ld, should be %ld", down.packetIndex, crcCheck, down.CRCCheck);
|
ESP_LOGE(TAG, "Received BAD CRC for packet %d, crc is %ld, should be %ld", down.packetIndex, crcCheck, down.CRCCheck);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -212,9 +237,11 @@ void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t crc = esp_rom_crc32_le(0, &(buf[0]) + sizeof(DownBoundPacket), payloadSize);
|
uint32_t crc = esp_rom_crc32_le(0, &(buf[0]) + sizeof(DownBoundPacket), payloadSize);
|
||||||
|
|
||||||
|
|
||||||
send_ack(down.packetIndex, crc);
|
if (down.packetType != DownlinkPacketType_ACK && down.packetType != DownlinkPacketType_Telemetry)
|
||||||
|
{
|
||||||
|
send_ack(down.packetIndex, crc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lora_comms_task(void *pvParameters)
|
void lora_comms_task(void *pvParameters)
|
||||||
@@ -240,10 +267,10 @@ void lora_comms_task(void *pvParameters)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t spreadingFactor = 7;
|
uint8_t spreadingFactor = 8;
|
||||||
uint8_t bandwidth = SX126X_LORA_BW_250_0;
|
uint8_t bandwidth = SX126X_LORA_BW_250_0;
|
||||||
uint8_t codingRate = SX126X_LORA_CR_4_8;
|
uint8_t codingRate = SX126X_LORA_CR_4_8;
|
||||||
uint16_t preambleLength = 8;
|
uint16_t preambleLength = 4;
|
||||||
bool crcOn = true;
|
bool crcOn = true;
|
||||||
bool invertIrq = false;
|
bool invertIrq = false;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user