У меня есть вопрос о стоимости подписки с сервера Издательство работает.
Я борюсь с подпиской. Я отправляю значение с сервера Thingworx, я вижу значение в MQTTlens, но не вижу его в Arduino. Я использую PubSubClient.h.
WiFiEspClient espClient;
PubSubClient client(espClient);
void callback(char* topic, byte* payload, unsigned int length) //print any message received for subscribed topic
{
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
}
Serial.println();
}
void WiFiConnect() {
if (WiFi.status() == WL_NO_SHIELD) // check for the presence of the shield
{
Serial.println("WiFi shield not present");
while (true);// don't continue
}
while ( status != WL_CONNECTED) // attempt to connect to WiFi network
{
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network
}
Serial.println("You're connected to the network"); // you're connected now
client.setServer(server, 1883); //connect to MQTT server
client.setCallback(callback);
}
void reconnect(){
while (!client.connected()) // Loop until we're reconnected
{
Serial.print("Attempting MQTT connection...");
if (loadDataFromSensors()) {
}
if (client.connect("ESP8266Client")) // Attempt to connect, just a name to identify the client
{
Serial.println("connected");
client.subscribe("/Thingworx/PRM9_iot_pub/movespool");
client.publish("/Thingworx/PRM9_iot/SpoolPosition", spoolposString);
client.publish("/Thingworx/PRM9_iot/Teplota", tempString);
client.publish("/Thingworx/PRM9_iot/Vlhkost", humidString);
client.publish("/Thingworx/PRM9_iot/Tlak", presString);
}
else
{
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 2 seconds");
delay(2000);
}
}
}
Может кто-нибудь помочь?
Спасибо.