Hey,
I'm currently working on a NodeMCU and wanted to build a Battery monitoring System. I've built a Voltage Divider that divides the 5V to about 2-3V. I now want to send the analog Value of a variable(raw) via MQTT to my MQTT broker. That is currently my problem spot with the code:
void callback(char* topic, byte* payload, unsigned int length) {
char raw[3] = {analogRead(Akku)};
if ((analogRead(Akku)) >= 810) {
Serial.println("5V");
client.publish("Sportraum/Strom/state", "Voll");
} else {
client.publish("topic/test", "Battery");
Serial.print("Raw Voltage: ");
Serial.println(raw);
client.publish("topic/test", raw);
}
delay(3000);
}
I can not understand why it won't transmit human-readable values via Serial and why the values are so of in my broker. I tried resolving some problems myself, visible at the line with "char" what I would have coded with "int" but it hasn't worked with int and won't cause by the conversion error that occurred beforehand. I hope somebody is able to help me. Stay Safe and thanks in advance