-
Notifications
You must be signed in to change notification settings - Fork 13.3k
When a second NodeMCU ESP8266 is powered up, NEITHER will send readings to MQTT server #4765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is not the place to ask questions like this, this is for reporting bugs in the Arduino-core for the ESP8266. Use esp8266.com for general questions and help. That said, your problem is pretty simple: you're starting your Nodemcus as both AP and STA and so they end up trying to connect to one-another. Use WiFi.mode(WIFI_STA); before WiFi.begin(ssid, password); to make them act as plain STA. |
@WereCatf , That said: I tried your advice and now the Ardino just print dots in the serial monitor, so it is not connecting at all....... So if you could point me in the correct direction where to ask a question from people that would be willing to help, I will appreciate it. |
@fritserasmus please don't be so ironic - in the issue template you have been pointed to Issue policy ( https://github.com/esp8266/Arduino/blob/master/POLICY.md ) did you read this? First sentence in the issue template after "delete below" is "If your issue is a general question, starts similar to "How do I..", is related to 3rd party libs, or is related to hardware, please discuss at a community forum like esp8266.com." so correct direction where to ask has been already given. |
The explanation and channels are in the issue POLICY doc found in the root of this repo, and in the issue template, which you saw when opening this issue, and which also links to the issue POLICY doc. Be aware that this is a community effort, so the official channels are community channels. |
Basic Infos
Platform
Settings in IDE
Problem Description
Detailed problem description goes here.
I have two Node-MCU's and will be adding two more.
UBUNTU 16.04 Server is my MQTT server also running mySQL
I have been using the same IDE for both temp sensors: DS18B20 but changing the topic to be different so I can have separated INSERT SQL Scripts.
When only one Noe-MCU is connected either via PC or directly from power it will send the reading out. It will show on the Serial monitor and MQTT SUB and update mySQL table. This is the rule for either of the two Node-MCU's connected.
The IP Address stays the same when connected to PC or direct to power supply
(I checked with (Advanced IP Scanner to make sure I have the unit by confirming MAC Addresses)
As soon as the second Node-MCU starts up, NO Temperature readings reaches the Serial port or MQTT or mySQL
With Node-MCU's connected in turn for a a minute it will update with the correct record that distinguish between the different sensors.
MCVE Sketch
// DS18B20_WITH_ESP8266_NODEMCU_Upload_OWN_MQTT_FER_V2_G1
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Streaming.h>
#define ONE_WIRE_BUS D4 // DS18B20 pin
const char* ssid = "myaccesspoint";
const char* password = "accesspointpw";
const char* mqtt_server = "192.168.1.110";
const char* mqtt_username = "mqttuser";
const char* mqtt_password = "0000";
const char* mqtt_topic = "/18561/geyser1/temp";
WiFiClient espClient;
PubSubClient client(espClient);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
char temperatureString[6];
void setup() {
// setup serial port
Serial.begin(115200);
// setup WiFi
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
// setup OneWire bus
DS18B20.begin();
}
void setup_wifi() {
delay(300);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("ESP8266Client", mqtt_username, mqtt_password)) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 2 seconds before retrying
delay(2000);
}
}
}
float getTemperature() {
Serial << "Requesting DS18B20 temperature..." << endl;
float temp;
do {
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
delay(500);
} while (temp == 85.0 || temp == (-127.0));
return temp;
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
float temperature = getTemperature();
// convert temperature to a string with two digits before the comma and 2 digits for precision
dtostrf(temperature, 2, 2, temperatureString);
// send temperature to the serial console
Serial << "Sending temperature: " << temperatureString << endl;
// send temperature to the MQTT topic
client.publish(mqtt_topic, temperatureString);
delay(500);
}
Debug Messages
The text was updated successfully, but these errors were encountered: