{"action":"created","issue":{"url":"https://api.github.com/repos/knolleary/pubsubclient/issues/236","repository_url":"https://api.github.com/repos/knolleary/pubsubclient","labels_url":"https://api.github.com/repos/knolleary/pubsubclient/issues/236/labels{/name}","comments_url":"https://api.github.com/repos/knolleary/pubsubclient/issues/236/comments","events_url":"https://api.github.com/repos/knolleary/pubsubclient/issues/236/events","html_url":"https://github.com/knolleary/pubsubclient/issues/236","id":202309269,"number":236,"title":" ESP8266 + ARDUINO UNO R3 problems after client.subscribe() instruction","user":{"login":"Muplex","id":25262524,"avatar_url":"https://avatars.githubusercontent.com/u/25262524?v=3","gravatar_id":"","url":"https://api.github.com/users/Muplex","html_url":"https://github.com/Muplex","followers_url":"https://api.github.com/users/Muplex/followers","following_url":"https://api.github.com/users/Muplex/following{/other_user}","gists_url":"https://api.github.com/users/Muplex/gists{/gist_id}","starred_url":"https://api.github.com/users/Muplex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Muplex/subscriptions","organizations_url":"https://api.github.com/users/Muplex/orgs","repos_url":"https://api.github.com/users/Muplex/repos","events_url":"https://api.github.com/users/Muplex/events{/privacy}","received_events_url":"https://api.github.com/users/Muplex/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-01-21T11:07:42Z","updated_at":"2017-02-03T13:53:15Z","closed_at":null,"body":"Hello,\r\nI've got a problem after perform client.subscribe() instruction.\r\nThe blue led on the ESP8266 - esp01 start to flash very fast and i miss most of the client.publish() messages published from MQTTFX.\r\n\r\nESP specs are:\r\nAT version:1.1.0.0(May 11 2016 18:09:56)\r\nSDK version:1.5.4(baaeaebb)\r\nAi-Thinker Technology Co. Ltd.\r\nJun 13 2016 11:29:20\r\n\r\nthe code i've run is \r\n```\r\n/*\r\n  MQTT DHT22, when \"temperature, c\" is sent it returns the temperature in celcius\r\n  when \"humidity\" is sent it returns the humidity as measured by the DHT22\r\n  the signal pin is connected to a pull-ip resistor and GPIO 2\r\n*/\r\n\r\n#include <WiFiEsp.h>\r\n#include <WiFiEspClient.h>\r\n#include <WiFiEspUdp.h>\r\n#include <PubSubClient.h>\r\n#include \"SoftwareSerial.h\"\r\n#include <DHT.h>\r\n\r\n#define DHTTYPE DHT11\r\n#define DHTPIN  2\r\n\r\n// Update these with values suitable for your network.\r\n\r\nchar* ssid = \"ZEDGEAR50\";\r\nchar* password = \"zesta24985\";\r\nconst char* mqtt_server = \"10.0.0.8\";\r\nconst char* clientID = \"NodeTest\";\r\nconst char* outTopic = \"NodeTestout\";\r\nconst char* inTopic = \"NodeTestin\";\r\n\r\nint status = WL_IDLE_STATUS;   // the Wifi radio's status\r\n\r\n// Initialize DHT sensor \r\n// NOTE: For working with a faster than ATmega328p 16 MHz Arduino chip, like an ESP8266,\r\n// you need to increase the threshold for cycle counts considered a 1 or 0.\r\n// You can do this by passing a 3rd parameter for this threshold.  It's a bit\r\n// of fiddling to find the right value, but in general the faster the CPU the\r\n// higher the value.  The default for a 16mhz AVR is a value of 6.  For an\r\n// Arduino Due that runs at 84mhz a value of 30 works.\r\n// This is for the ESP8266 processor on ESP-01 \r\nDHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266\r\n\r\nfloat humidity, temp_c;  // Values read from sensor\r\n// Generally, you should use \"unsigned long\" for variables that hold time\r\nunsigned long previousMillis = 0;        // will store last temp was read\r\nconst long interval = 2000;              // interval at which to read sensor\r\n \r\nWiFiEspClient espClient;\r\nPubSubClient client(espClient);\r\nchar msg[50];\r\n\r\nSoftwareSerial soft(8, 9); // RX, TX\r\n\r\nvoid setup() {\r\n  Serial.begin(9600);\r\n  soft.begin(9600);\r\n  // initialize ESP module\r\n  WiFi.init(&soft);\r\n  setup_wifi();\r\n  client.setServer(mqtt_server, 1883);\r\n  client.setCallback(callback);\r\n  dht.begin();           // initialize temperature sensor\r\n\r\n}\r\n\r\nvoid loop() {\r\n\r\n  if (!client.connected()) {\r\n    reconnect();\r\n  }\r\n  client.loop();\r\n}\r\n\r\nvoid setup_wifi() {\r\n\r\n  // check for the presence of the shield\r\n  if (WiFi.status() == WL_NO_SHIELD) {\r\n    Serial.println(\"WiFi shield not present\");\r\n    // don't continue\r\n    while (true);\r\n  }\r\n  \r\n  delay(10);\r\n  // We start by connecting to a WiFi network\r\n  Serial.println();\r\n  Serial.print(\"Connecting to \");\r\n  Serial.println(ssid);\r\n  \r\n  // attempt to connect to WiFi network\r\n  while ( status != WL_CONNECTED) {\r\n    Serial.print(\"Attempting to connect to WPA SSID: \");\r\n    Serial.println(ssid);\r\n    // Connect to WPA/WPA2 network\r\n    status = WiFi.begin(ssid, password);\r\n  }\r\n\r\n  // you're connected now, so print out the data\r\n  Serial.println(\"\");\r\n  Serial.println(\"WiFi connected\");\r\n  Serial.println(\"IP address: \");\r\n  Serial.println(WiFi.localIP());\r\n}\r\n\r\nvoid callback(char* topic, byte* payload, unsigned int length) {\r\n  // Conver the incoming byte array to a string\r\n  payload[length] = '\\0'; // Null terminator used to terminate the char array\r\n  String message = (char*)payload;\r\n\r\n  Serial.print(\"Message arrived on topic: [\");\r\n  Serial.print(topic);\r\n  Serial.print(\"], \");\r\n  Serial.println(message);\r\n\r\n  if(message == \"temperature, c\"){\r\n    gettemperature();\r\n    Serial.print(\"Sending temperature:\");\r\n    Serial.println(temp_c);\r\n    dtostrf(temp_c , 2, 2, msg);\r\n    client.publish(outTopic, msg);\r\n  } else if (message == \"humidity\"){\r\n    gettemperature();\r\n    Serial.print(\"Sending humidity:\");\r\n    Serial.println(humidity);\r\n    dtostrf(humidity , 2, 2, msg);\r\n    client.publish(outTopic, msg);\r\n  }\r\n\r\n}\r\n\r\nvoid reconnect() {\r\n  // Loop until we're reconnected\r\n  while (!client.connected()) {\r\n    Serial.print(\"Attempting MQTT connection...\");\r\n    // Attempt to connect\r\n    if (client.connect(clientID)) {\r\n      Serial.println(\"connected\");\r\n      // Once connected, publish an announcement...\r\n      client.publish(outTopic, clientID);\r\n      // ... and resubscribe\r\n      client.subscribe(inTopic);\r\n    } else {\r\n      Serial.print(\"failed, rc=\");\r\n      Serial.print(client.state());\r\n      Serial.println(\" try again in 5 seconds\");\r\n      // Wait 5 seconds before retrying\r\n      delay(5000);\r\n    }\r\n  }\r\n}\r\n\r\nvoid gettemperature() {\r\n  // Wait at least 2 seconds seconds between measurements.\r\n  // if the difference between the current time and last time you read\r\n  // the sensor is bigger than the interval you set, read the sensor\r\n  // Works better than delay for things happening elsewhere also\r\n  unsigned long currentMillis = millis();\r\n \r\n  if(currentMillis - previousMillis >= interval) {\r\n    // save the last time you read the sensor \r\n    previousMillis = currentMillis;   \r\n\r\n    // Reading temperature for humidity takes about 250 milliseconds!\r\n    // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)\r\n    humidity = dht.readHumidity();          // Read humidity (percent)\r\n    temp_c = dht.readTemperature();     // Read temperature as Celcius\r\n    // Check if any reads failed and exit early (to try again).\r\n    if (isnan(humidity) || isnan(temp_c)) {\r\n      Serial.println(\"Failed to read from DHT sensor!\");\r\n      return;\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nmaybe you have to know that to make ESP work properly I change the baudrate to 9600.\r\n\r\nAll is almost good. the problem is the loosing of information after client.subscribe(). Can you halp me to understand the problem? For you the firmware are good ?"},"comment":{"url":"https://api.github.com/repos/knolleary/pubsubclient/issues/comments/277251332","html_url":"https://github.com/knolleary/pubsubclient/issues/236#issuecomment-277251332","issue_url":"https://api.github.com/repos/knolleary/pubsubclient/issues/236","id":277251332,"user":{"login":"Muplex","id":25262524,"avatar_url":"https://avatars.githubusercontent.com/u/25262524?v=3","gravatar_id":"","url":"https://api.github.com/users/Muplex","html_url":"https://github.com/Muplex","followers_url":"https://api.github.com/users/Muplex/followers","following_url":"https://api.github.com/users/Muplex/following{/other_user}","gists_url":"https://api.github.com/users/Muplex/gists{/gist_id}","starred_url":"https://api.github.com/users/Muplex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Muplex/subscriptions","organizations_url":"https://api.github.com/users/Muplex/orgs","repos_url":"https://api.github.com/users/Muplex/repos","events_url":"https://api.github.com/users/Muplex/events{/privacy}","received_events_url":"https://api.github.com/users/Muplex/received_events","type":"User","site_admin":false},"created_at":"2017-02-03T13:53:15Z","updated_at":"2017-02-03T13:53:15Z","body":"I will try and let you know if issue solves"}}
{"actor":{"display_login":"Muplex"}}