In the serial port I see (Its Ok):
Type: ND, ID: 3 | LTD: 59916757, LNG: 33590709, ALT: 127690 | CRC: 0xE0
I am successfully sending data over the air.
=================================
On the receiving side my code is:
I have two ESP32 modules and two LoRa E32-443T33D.
One set sends data (structure).
The second set receive data.
I output a formatted string with the values in the structure to the console.
Both structures are the same (transmitter and receiver).
The types of variables in the structure are also the same.
For example, I send dev_id = 1, and receive 54.
Another question arose about calculating the checksum of the structure…
In the transmitter, I form a static structure (for testing) and send it.
#pragma pack(push, 1)
struct LoraData {
char type[3] = "ND"; // Тип структуры (навигационные данные)
uint8_t dev_id = 1; // ID Устройства
int32_t latitude = 2; // Широта (миллионные доли градуса)
int32_t longitude = 3; // Долгота (миллионные доли градуса)
int32_t altitude = 4; // Высота (миллиметр)
int32_t speed = 5; // Скорость
int32_t course = 6; // Курс (тысячные доли градуса по часовой стрелке от севера)
uint8_t num_satellites = 7; // Количество видимых спутников (штук)
uint8_t hdop = 8; // Точность позиционирования (десятые доли, 11 соответствует 1.1)
uint16_t sdeg = 9; // Текущий угол серво машинки
uint8_t crc8; // Контрольная сумма структуры
} lora_data;
#pragma pack(pop)
lora_data.crc8 = get_crc_8((const char *)&lora_data, sizeof(lora_data) - sizeof(lora_data.type) - sizeof(lora_data.crc8));
ResponseStatus response_status = LORA_E32.sendFixedMessage(BASE_ADDR_H, BASE_ADDR_L, BASE_RF_CHANNEL, &lora_data, sizeof(LoraData));
The checksum is 0x88 (without the type and crc8 fields)
Receiver code
void Task_LoRa(void) {
if (LORA_E32.available() > 1) {
/* Извлекаем тип пакета */
char type[3];
ResponseContainer rs = LORA_E32.receiveInitialMessage(sizeof(type));
String type_str = rs.data;
if (type_str == "ND") {
/* Пакет с навигационными данными */
/* Создаем структуру с точным количеством выделенной памяти */
#pragma pack(push, 1)
struct NavData {
uint8_t dev_id; // ID Устройства
int32_t latitude; // Широта (миллионные доли градуса)
int32_t longitude; // Долгота (миллионные доли градуса)
int32_t altitude; // Высота (миллиметр)
int32_t speed; // Скорость
int32_t course; // Курс (тысячные доли градуса по часовой стрелке от севера)
uint8_t num_satellites; // Количество видимых спутников (штук)
uint8_t hdop; // Точность позиционирования (десятые доли, 11 соответствует 1.1)
uint16_t sdeg; // Текущий угол серво машинки
uint8_t crc8; // Контрольная сумма структуры
} nav_data;
#pragma pack(pop)
ResponseStructContainer rsc = LORA_E32.receiveMessage(sizeof(NavData));
nav_data = *(NavData *)rsc.data;
/* Проверяем контрольную сумму */
uint8_t crc8_calc = get_crc_8((const char *)&nav_data, sizeof(nav_data) - sizeof(nav_data.crc8));
char buffer_crc[256];
snprintf(buffer_crc, sizeof(buffer_crc),
"ID: %d | Rem CRC8: 0x%02X | Cal CRC8: 0x%02X",
nav_data.dev_id, nav_data.crc8, crc8_calc);
SEND_DEBUG_MSG(buffer_crc);
if (crc8_calc != nav_data.crc8) {
SEND_DEBUG_MSG("ER! CRC8 Navigation Data");
rsc.close();
return;
}
rsc.close();
} else {
Serial.println("Something Goes Wrong!");
}
}
}
But the checksum is 0x04 (without crc8 fields)
I use receiveInitialMessage.
What could be the problem with the checksum calculation?
The calculation function is the same on both sides.
This reply was modified 1 month, 1 week ago by poe.
Maintaining a repository (or site or forum) is a lot like tending to a garden - it requires constant care and attention to keep it thriving. If you're a skilled gardener (or coder!) and want to help keep our repository blooming, we'd love to have you on board! We're also looking for talented writers and forum moderators to help us grow our community. Interested in joining our team? Don't hesitate to reach out and let us know how you can contribute!
Are you a fan of electronics or programming? Share your knowledge with others, write a simple tutorial or how to make a great project Contact me: share_your_ideas@mischianti.org
The content displayed on this website is protected under a CC BY-NC-ND license. Visitors are prohibited from using, redistributing, or altering any content from this website for commercial purposes, including generating revenue through advertising. Any unauthorized use is a violation of the license terms and legal action may be taken against individuals or entities found to be in violation.
You must also provide the link to the source.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.