![]() |
Arduino demo source code for LoRa "Receiver" - Printable Version +- Smart Home Automation Forum (https://www.kincony.com/forum) +-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20) +--- Forum: KinCony ALR (https://www.kincony.com/forum/forumdisplay.php?fid=59) +--- Thread: Arduino demo source code for LoRa "Receiver" (/showthread.php?tid=6166) |
Arduino demo source code for LoRa "Receiver" - admin - 07-21-2024 Code: #include <LoRa.h> before use this code, need to install LoRa SX1278 arduino library firstly. RE: Arduino demo source code for LoRa "Receiver" - kendo - 08-12-2024 i have done these instruction. it doesn't work. Error Msg in Arduino: -------------------------------------------------------------------------------------- LoRa_Receicer_KC868:7:10: fatal error: LoRa.h: No such file or directory #include <LoRa.h> ^~~~~~~~ compilation terminated. exit status 1 LoRa.h: No such file or directory -------------------------------------------------------------------------------------------- the lib is installed! RE: Arduino demo source code for LoRa "Receiver" - kendo - 08-12-2024 I found the Solution: I had to download the ZIP-File and then to use the Option: ADD Zip Library downloaded from https://github.com/sandeepmistry/arduino-LoRa RE: Arduino demo source code for LoRa "Receiver" - kendo - 08-12-2024 I have found the solution: I had to download the ZIP-File and then to use the Option: ADD Zip Library download from: https://github.com/sandeepmistry/arduino-LoRa RE: Arduino demo source code for LoRa "Receiver" - admin - 08-12-2024 ok, good. RE: Arduino demo source code for LoRa "Receiver" - maso - 12-03-2024 I was too optimistic and full-bodied. Unfortunately, HA MQTT doesn't work the way I want it to. Somehow I didn't quite understand the HA topics, as some are not written to mqtt broker. Can you help me please to get my code right? I tried to re-code your topics which I see in the serial and in the mqtt broker via explorer: Here is my code. and only the status is written, not the sensor parameters, which I do not understand // Register new device and send discovery topics void registerDevice(int address, const LoRaData& data) { if (registeredNodes[address]) return; Serial.printf("New device %08X to be registered in MQTT Broker:\n", address); char configTopic[180]; char payload[1024]; char stateTopic[50]; char commandTopic[60]; // State-& Command-Topics for switch & Sensors //sprintf(stateTopic, "homeassistant/sensor/alrha%08X/params/state", address); //sprintf(commandTopic, "homeassistant/sensor/alrha%08X/params/set", address); sprintf(commandTopic, "homeassistant/sensor/alrhaDCDA0C7B7BD4/params/set", address); sprintf(stateTopic, "homeassistant/sensor/alrhaDCDA0C7B7BD4/params/state", address); // Relay sprintf(configTopic, "homeassistant/switch/alr_ALR_switch/config"); snprintf(payload, sizeof(payload), "{\"name\":\"relay\"," "\"state_on\":1," "\"state_off\":0," "\"payload_on\":\"1\"," "\"payload_off\":\"0\"," "\"value_template\":\"{{ value_json.relay.on | string }}\"," "\"state_topic\":\"%s\"," "\"command_topic\":\"%s\"," "\"unique_id\":\"alr_switch\"," "\"device\":{" "\"identifiers\":[\"alr\"]," "\"name\":\"alr evb\"," "\"model\":\"ALR\"," "\"manufacturer\":\"KinCony\"" "}}", stateTopic, commandTopic); Serial.printf("Config topic: %s\nPayload: %s\n", configTopic, payload); mqttClient.publish(configTopic, payload); Serial.println("MQTT Switch topic configured"); // Sensors const char* sensorNames[] = {"inword", "outword", "analog_A1", "analog_A2", "analog_A3", "analog_A4", "DS18B20"}; const char* valueTemplates[] = {"{{ value_json.inword }}", "{{ value_json.outword }}", "{{ value_json.analog_f[0] }}", "{{ value_json.analog_f[1] }}", "{{ value_json.analog_f[2] }}", "{{ value_json.analog_f[3] }}", "{{ value_json.wire1_data0 }}"}; for (int i = 0; i < 7; i++) { delay(800); //sprintf(configTopic, "homeassistant/sensor/alrha%08X/alr_ALR_param%d/config", address, i); sprintf(configTopic, "homeassistant/sensor/alr_ALR_param%d/config", i); snprintf(payload, sizeof(payload), "{\"name\":\"%s\"," "\"unit_of_measurement\":\"%s\"," "\"value_template\":\"%s\"," "\"state_topic\":\"%s\"," "\"command_topic\":\"%s\"," "\"unique_id\":\"alr_param%d\"," "\"device\":{" "\"identifiers\":[\"alr\"]," "\"name\":\"alr evb\"," "\"model\":\"ALR\"," "\"manufacturer\":\"KinCony\"" "}}", sensorNames[i], // Name des Sensors (i > 1 && i < 6) ? "V" : " ", // Einheit (z. B. Volt) für 4 ADs valueTemplates[i], // Template für den Wert stateTopic, // State Topic commandTopic, // Command Topic i); // Eindeutige ID Serial.printf("Config topic: %s\nPayload: %s\n", configTopic, payload); mqttClient.publish(configTopic, payload); } registeredNodes[address] = true; Serial.printf("All Device %08X Sonsor Topics registered.\n", address); } // update MQTT-State values void updateMQTTState(int address, const LoRaData& data) { StaticJsonDocument<256> jsonDoc; jsonDoc["self_addr"] = data.self_addr; jsonDoc["inword"] = data.inword; jsonDoc["outword"] = data.outword; JsonArray analogF = jsonDoc.createNestedArray("analog_f"); for (int i = 0; i < 4; i++) analogF.add(data.analog_f[i]); jsonDoc["wire1_data0"] = data.wire1_data0; jsonDoc["relay"]["on"] = data.relay_on; char buffer[512]; serializeJson(jsonDoc, buffer, sizeof(buffer)); char stateTopic[50]; //sprintf(stateTopic, "homeassistant/sensor/alrha%08X/params/state", address); sprintf(stateTopic, "homeassistant/sensor/alrhaDCDA0C7B7BD4/params/state"); // MQTT-Payload serial ausgeben Serial.print("MQTT State Updated:"); Serial.println(buffer); Serial.println(); // Fügt einen CR ein // MQTT-Payload senden mqttClient.publish(stateTopic, buffer); } RE: Arduino demo source code for LoRa "Receiver" - maso - 12-05-2024 I found the problem. the config len of the mqtt buffer is very high. This Line helped! mqttClient.setBufferSize(512); increase from 256 to 512 RE: Arduino demo source code for LoRa "Receiver" - admin - 12-05-2024 ok, good. |