I am trying to make a smart bulb using ESP8266, Firebase and MIT app inventor. My problem is this: My esp8266 is unable to connect to WiFi. My router has a 5G band and a 2.4G band and I am trying to connect to the 2.4G band. My code is the following:
You might try setting it to station mode. From the example code...
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
I tried your code and the WiFi network is showing up as visible, but when I try to connect to it using this code:
#include <FastLED.h>
#include <DHT.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Firebase_ESP_Client.h>
#define LED_PIN D8
#define NUM_LEDS 9
#define FASTLED_ESP8266_D1_PIN_ORDERz
CRGB l[NUM_LEDS];
DHT dht(D4, DHT11);
float t = 0.0;
float h = 0.0;
//Provide the token generation process info.
#include "addons/TokenHelper.h"
//Provide the RTDB payload printing info and other helper functions.
#include "addons/RTDBHelper.h"
// Insert your network credentials
#define WIFI_SSID "xxx"
#define WIFI_PASSWORD "xxx"
// Insert Firebase project API Key
#define API_KEY "xxx"
// Insert RTDB URLefine the RTDB URL */
#define DATABASE_URL "https://desk123-default-rtdb.firebaseio.com/"
//Define Firebase Data object
FirebaseData fbdo;
FirebaseData fbdR;
FirebaseData fbdG;
FirebaseData fbdB;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
String intValue;
String red;
String green;
String blue;
float floatValue;
bool signupOK = false;
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(l, NUM_LEDS);
dht.begin();
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
/* Assign the api key (required) */
config.api_key = API_KEY;
/* Assign */
config.database_url = DATABASE_URL;
/* Sign up */
if (Firebase.signUp(&config, &auth, "", "")) {
Serial.println("ok");
signupOK = true;
}
else {
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
}
void loop() {
if (Firebase.ready() && signupOK && (millis() - sendDataPrevMillis > 1000 || sendDataPrevMillis == 0)) {
sendDataPrevMillis = millis();
Serial.println("Initializing");
t = dht.readTemperature();
h = dht.readHumidity();
if (isnan(t) || isnan(h)) {
Serial.println("ERROR");
}
if (Firebase.RTDB.setFloat(&fbdo, "Data/temp", t)) {
Serial.println("PASSED");
Serial.println("PATH: " + fbdo.dataPath());
Serial.println("TYPE: " + fbdo.dataType());
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
if (Firebase.RTDB.setFloat(&fbdo, "Data/humidity", h)) {
Serial.println("PASSED");
Serial.println("PATH: " + fbdo.dataPath());
Serial.println("TYPE: " + fbdo.dataType());
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
if (Firebase.RTDB.getInt(&fbdo, "/Data/led") && Firebase.RTDB.getInt(&fbdR, "/Data/red" && Firebase.RTDB.getInt(&fbdG, "/Data/green" && Firebase.RTDB.getInt(&fbdB, "/Data/blue")))) {
Serial.println("Path existant");
if (fbdo.dataType() == "int" || fbdo.dataType() == "float" || fbdo.dataType() == "string") {
Serial.println(fbdo.dataType());
intValue = fbdo.stringData();
Serial.println(intValue);
if (intValue == "1" || intValue == "1.00") {
red = fbdR.stringData();
blue = fbdB.stringData();
green = fbdG.stringData();
for (int i = 0; i <= NUM_LEDS; i++) {
l[i] = CRGB(red.toInt(), green.toInt(), blue.toInt());
FastLED.show();
}
} else {
for (int i = 0; i <= NUM_LEDS; i++) {
FastLED.clear();
FastLED.show();
}
}
}
}
else {
Serial.println(fbdo.errorReason());
}
}
}
It is just printing a long row of dots. Any ideas as to what might be going wrong? I have double checked my WiFi password and it is correct, as is the SSiD
#include <ESP8266WiFi.h> // Include the Wi-Fi library
const char* ssid = "SSID"; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "PASSWORD"; // The password of the Wi-Fi network
void setup() {
Serial.begin(115200); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
}
void loop() { }
@ZX80@oldcurmudgeon Thank you for trying to help! In the end, it turned out that the 2.4G band had a different password than the 5G band. Thank you for your help!