Rupakpoddar / FirebaseArduino

Enables Firebase Realtime Database connectivity on the ESP8266, ESP32, Arduino UNO R4 WiFi.
https://www.arduino.cc/reference/en/libraries/firebase/
MIT License
1 stars 2 forks source link

Librarz not working with Uno R4 Wifi #4

Open JacobEPTechnologies421 opened 1 month ago

JacobEPTechnologies421 commented 1 month ago

/* This example connects to an unencrypted WiFi network. Then it prints the MAC address of the WiFi module, the IP address obtained, and other network details.

created 13 July 2010 by dlf (Metodo2 srl) modified 31 May 2012 by Tom Igoe

Find the full UNO R4 WiFi Network documentation here: https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples#connect-with-wpa */

include

include

include

include

include

include "WiFiS3.h"

include "arduino_secrets.h"

///////please enter your sensitive data in the Secret tab/arduino_secrets.h char ssid[] = SECRET_SSID; // your network SSID (name) char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) int status = WL_IDLE_STATUS; // the WiFi radio's status

define REFERENCE_URL "https://ducan-e1c1c-default-rtdb.europe-west1.firebasedatabase.app"

define ONE_WIRE_BUS 6 // GPIO pin for DS18B20

Firebase fb(REFERENCE_URL);

OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire);

// Variables for DS18B20 sensors DeviceAddress sensor1, sensor2, sensor3;

bool sensorFound = false;

void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only }

// check for the WiFi module: if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); // don't continue while (true); }

String fv = WiFi.firmwareVersion(); if (fv < WIFI_FIRMWARE_LATEST_VERSION) { Serial.println("Please upgrade the firmware"); }

// attempt to connect to WiFi network: while (status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network: status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:
delay(10000);

}

// you're connected now, so print out the data: Serial.print("You're connected to the network"); printCurrentNet(); fb.setString("Example/myString", "Hello World!"); sensors.begin();

// Check if at least 3 sensors are found if (sensors.getDeviceCount() < 3) { Serial.println("Error: Less than 3 DS18B20 sensors found."); }

// Assign addresses to sensor variables if (!sensors.getAddress(sensor1, 0) || !sensors.getAddress(sensor2, 1) || !sensors.getAddress(sensor3, 2)) { Serial.println("Error: Failed to retrieve sensor addresses."); }

}

void loop() { sensors.requestTemperatures();

// Read temperatures from the sensors float temp1 = sensors.getTempC(sensor1); float temp2 = sensors.getTempC(sensor2); float temp3 = sensors.getTempC(sensor3);

// Log temperature readings to the Serial monitor Serial.print("Sensor 1: "); Serial.print(temp1); Serial.print(" °C, Sensor 2: "); Serial.print(temp2); Serial.print(" °C, Sensor 3: "); Serial.print(temp3); Serial.println(" °C");

// Wait for 10 seconds before the next measurement delay(1000); }

Seems that the lib is not not responding to the board or am i making anzthing wrong

Rupakpoddar commented 1 month ago

Hello @JacobEPTechnologies421,

Thank you for reaching out. I was able to run the modified version of the code you provided and it worked as expected on an Arduino Uno R4 WiFi Board. Make sure your WiFi is working properly, and your Arduino board and libraries are up to date.

// #include <OneWire.h>
// #include <DallasTemperature.h>
#include <SPI.h>
#include <ArduinoJson.h>

#include <Firebase.h>
#include "WiFiS3.h"

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
#define REFERENCE_URL "https://ducan-e1c1c-default-rtdb.europe-west1.firebasedatabase.app"

// #define ONE_WIRE_BUS 6 // GPIO pin for DS18B20

Firebase fb(REFERENCE_URL);

// OneWire oneWire(ONE_WIRE_BUS);
// DallasTemperature sensors(&oneWire);

// Variables for DS18B20 sensors
// DeviceAddress sensor1, sensor2, sensor3;

bool sensorFound = false;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {

  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the data:
  Serial.println("You're connected to the network");
  // printCurrentNet();
  Serial.println(fb.setString("Example/myString", "Hello World!")); // 200: Success, else failed.
  // sensors.begin();

  // Check if at least 3 sensors are found
  // if (sensors.getDeviceCount() < 3) {
  //   Serial.println("Error: Less than 3 DS18B20 sensors found.");
  // }

  // Assign addresses to sensor variables
  // if (!sensors.getAddress(sensor1, 0) || !sensors.getAddress(sensor2, 1) || !sensors.getAddress(sensor3, 2)) {
  //   Serial.println("Error: Failed to retrieve sensor addresses.");
  // }

}

void loop() {
  // sensors.requestTemperatures();

  // Read temperatures from the sensors
  // float temp1 = sensors.getTempC(sensor1);
  // float temp2 = sensors.getTempC(sensor2);
  // float temp3 = sensors.getTempC(sensor3);

  // Log temperature readings to the Serial monitor
  // Serial.print("Sensor 1: ");
  // Serial.print(temp1);
  // Serial.print(" °C, Sensor 2: ");
  // Serial.print(temp2);
  // Serial.print(" °C, Sensor 3: ");
  // Serial.print(temp3);
  // Serial.println(" °C");

  // Wait for 10 seconds before the next measurement
  // delay(1000);
}
JacobEPTechnologies421 commented 1 month ago

hi, the issue still persits, with zour code I get a return value as 0

Rupakpoddar commented 1 month ago

Hello,

I'm unable to replicate the issue on my end, and it's unclear where the system might be failing. It could be something as simple as a VPN or firewall issue. To start with the basics, could you please upload the following code and share the output?

#include "WiFiS3.h"
#include "WiFiSSLClient.h"

char ssid[] = "your_SSID";        // Your network SSID (name)
char pass[] = "your_PASSWORD";    // Your network password

WiFiSSLClient client;
char server[] = "www.google.com";  // Server to connect to

void setup() {
  Serial.begin(115200);
  while (!Serial) { ; }  // Wait for serial port to connect

  // Check if the Wi-Fi module is present
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("WiFi module not found!");
    while (true);
  }

  // Check firmware version
  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please update the WiFi firmware!");
  }

  // Connect to Wi-Fi network
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print("Connecting to SSID: ");
    Serial.println(ssid);
    WiFi.begin(ssid, pass);
    delay(10000);  // Wait 10 seconds for connection
  }

  Serial.println("WiFi connected");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());

  // Connect to the server
  if (client.connect(server, 443)) {
    Serial.println("Connected to server");

    // Send HTTP GET request
    client.println("GET / HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  } else {
    Serial.println("Connection to server failed");
  }
}

void loop() {
  // Read and print server response
  while (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // Disconnect from the server
  if (!client.connected()) {
    Serial.println();
    Serial.println("Disconnecting...");
    client.stop();
    while (true);
  }
}