I'm using NodeMCU 0.9 My sketch crashes if the following 2 include are present in the sketch:

#include <PubSubClient.h>
#include <HX711.h>

I obtain a Soft WDT reset

If I do not use HX711 I can send message using mqtt. If I do not use PubSubClient I can read weight values from the load cell connected to the hx711 board without problem

The code crashes at the following line:

mqtt_client.connect("ESP8266Client", mqtt_user, mqtt_password)

Actually using this debugger suggested here the line that crashes is the following and it is inside the PubSubClient class:


It is a function already existing at ~/.arduino15/packages/esp8266/hardware/esp8266/2.4.1/libraries/ESP8266WiFi/src/WiFiClient.cpp line 21

Here I paste my code so you can reproduce it and tell me if you have the same problem:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include "HX711.h"

#define wifi_ssid "mqtt"
#define wifi_password "testmqtt"

#define mqtt_server "THE.IP.OF.MQTT"
#define mqtt_user "USER"
#define mqtt_password "PSW"

#define humidity_topic "sensor/humidity"
#define temperature_topic "sensor/temperature"
#define weight_topic "sensor/weight"

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
  client.setServer(mqtt_server, 1883);

void setup_wifi() {
  // We start by connecting to a WiFi network
  Serial.print("Connecting to ");

  WiFi.begin(wifi_ssid, wifi_password);

  while (WiFi.status() != WL_CONNECTED) {

  Serial.println("WiFi connected");
  Serial.println("IP address: ");

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    // If you do not want to use a username and password, change next line to
    // if (client.connect("ESP8266Client")) {
    if (client.connect("ESP8266Client", mqtt_user, mqtt_password)) {
    } else {
      Serial.print("failed, rc=");
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying

long lastMsg = 0;
float temp = 0.0;
float hum = 0.0;
float diff = 1.0;

void loop() {
  if (!client.connected()) {

  long now = millis();
  if (now - lastMsg > 1000) {
    lastMsg = now;

    float newTemp = 456;
    float newHum = 123;

    temp = newTemp+1;
    Serial.print("New temperature:");
    client.publish(weight_topic, String(temp).c_str(), true);

It works if you comment the initial include

PS: Nothing change if HX711 is include as <...> or "..."

  • Have you read this? May 4 '18 at 2:15
  • Assuming that's the library you're using - you haven't specified - there's - github.com/olkal/HX711_ADC - which can be installed using Arduino IDE (whereas the one I referred to can not) May 4 '18 at 2:22
  • Thank you @JaromandaX Now I'm trying to use HX711_ADC. I'll try to adapt my code to this new library and update if it gives me problem
    – Timmy
    May 4 '18 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.