Closed Tomaszito closed 3 years ago
@Tomaszito, what example do you use? I do not see how the MqttClient
is initialized, please provide full code. Do you call the MqttClient::yield
regularly?
Hi. Thanks for your help. In my case the arduino softwer dont work properly. I remove arduin and reinstall, after that everithing works. So i think your library work well. Thanks for the library helped me a lot.
I have a problem with this code. I use the example code for my program. I add some pub topics and sub topics but the server freses out and cant connect.
void MQTTinitalization() { // this is on void setup Ethernet.init(W5500SS); Ethernet.begin(mac, ip); client.begin(mqttServer, net); client.onMessage(messageReceived); connect(); }
void MQTTroutine() {// this is on void loop client.loop(); if (!client.connected())connect(); sendMessage(); }
The client stays in this stage and my mosuito broquer writes me my ip is 172.34.0.34 but my ip was set to 192.168.0.194 Some times the server connect up but some times stuck on a connect...... loop and try to connect with inwalid ip adress and my mosquito broker gives me back error. I dont know what can be a problem.
void connect() { Serial.print("connecting..."); while (!client.connect(deviceName, mqttUsername, mqttPassword)) { Serial.print("."); delay(1000); } client.subscribe("/home"); /for (int i = 0; i < OUTPUTSINSYSTEM; i++) client.subscribe(subsrcibeOut[i]); for (int i = 0; i < INPUTSINSYSTEM; i++) client.subscribe(subsrcibeIn[i]);/ } void messageReceived(String &topic, String &payload) { int payloadValue; payloadValue = payload.toInt(); Serial.println("incoming: " + topic + " - " + payload); for (int i = 0; i < OUTPUTSINSYSTEM; i++) { if (topic == subsrcibeOut[i] && OutAsTermostate[i] == false) { OUTPUTSTATES[i] = payloadValue; if (AtachSwitc[i] == true) { if (SwitchType[i] == true)INPUTINTEGRATION[OutSwitch[i]] = payloadValue; else INPUTSTATES[OutSwitch[i]] = payloadValue; } } } for (int i = 0; i < INPUTSINSYSTEM; i++) { if (topic == subsrcibeIn[i]) { if (InputAsSwitch[i] == true) { if (InputSwitchType[i] == true)INPUTSTATES[i] = payload.toInt(); else INPUTINTEGRATION[i] = payload.toInt(); } } } }
void sendMessage() { if (millis() - lastMillis > 5000) { client.publish("/hello", "world"); lastMillis = millis(); for (int i = 0; i < OUTPUTSINSYSTEM; i++)if (OutAsTermostate[i] == false)client.publish(publisOut[i], String(OUTPUTSTATES[i])); for (int i = 0; i < INPUTSINSYSTEM ; i++) { if (InputAsSwitch[i] == true) { if (InputType[i] == true) { client.publish(publisIn[i], String(analogRead(INPUTS[i])));//This gives back a raw analog data in 10bit (0-1023) with 5V reference } else { client.publish(publisIn[i], String(INPUTSTATES[i])); //This will gives back the input state that has been setted up you can modify this states on switch and push buttan also thanks to the input integration function that reverses the input eve on switch... } } }
ifdef TEMPSENSOR
endif*
} }