• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Value function error

Q&A Forum › Category: ESP32 › Value function error
0 Vote Up Vote Down
Patto asked 4 years ago

Hi
I am trying to use BatteryLevel as Value 5 for my bee hive monitor as per the tutorial
Visualize Your Sensor Readings from Anywhere in the World (ESP32/ESP8266 + MySQL + PHP)
I am using the code below and am getting the error

src\10 Frame Temp Hum WiFi.cpp:142:198: error: ‘batteryLevel’ cannot be used as a function

What should my value5 function be?

 


Start

#include <Arduino.h>

#include <WiFi.h>
#include <HTTPClient.h>

#include <HX711.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>

#define calibration_factor -18000.0
#define zero_factor 580130

#define LOADCELL_DOUT_PIN  23
#define LOADCELL_SCK_PIN  22

// Replace with your network credentials
const char* ssid     = “”;
const char* password = “”;

// REPLACE with your Domain name and URL path or IP address with path
const char* serverName = “”;

// Keep this API Key value to be compatible with the PHP code provided in the project page.
// If you change the apiKeyValue value, the PHP file /post-data.php also needs to have the same key
String apiKeyValue = “”;

#define DHTPIN 4     // Digital pin connected to the DHT sensor

#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

#define ONE_WIRE_BUS 15 // Data wire is connected to GPIO15

HX711 scale;

// Setup a oneWire instance to communicate with a OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

DeviceAddress sensor2 = { 0x28, 0x6A, 0x48, 0x7C, 0x0C, 0x00, 0x00, 0xC4 }; // long
//DeviceAddress sensor1 = { 0x28, 0xFA, 0x14, 0x7B, 0x0C, 0x00, 0x00, 0x47 }; //short

DHT dht(DHTPIN, DHTTYPE);

float batteryLevel = map(analogRead(33), 0.0f, 4095.0f, 0, 100);

// Time to sleep
uint64_t uS_TO_S_FACTOR = 1000000;  // Conversion factor for micro seconds to seconds
// sleep for 30 minutes = 1800 seconds
uint64_t TIME_TO_SLEEP = 1800;

// Get Sensor Readings
String getSensorReadings(){
sensors.requestTemperatures();
}

void setup() {
Serial.begin(115200);
sensors.begin();
dht.begin();
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.set_offset(zero_factor); //Zero out the scale using a previously known zero_factor

WiFi.begin(ssid, password);
Serial.println(“Connecting”);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.print(“Connected to WiFi network with IP Address: “);
Serial.println(WiFi.localIP());

// enable timer deep sleep
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
// start deep sleep for 1800 seconds (30 minutes)

}

void loop(){

Serial.print(“Requesting temperatures…”);
sensors.requestTemperatures(); // Send the command to get temperatures
// Serial.println(“DONE”);

//   Serial.print(“8 Frame Brood: “);
//   Serial.print(sensors.getTempC(sensor1));
//   Serial.print(“°C:    “);

Serial.print(“10 Frame Hive: “);
Serial.print(sensors.getTempC(sensor2));
Serial.print(“°C:    “);

Serial.print(“Hive  Weight “);
Serial.print(scale.get_units(), 1);
Serial.print(” Kgs      “);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println(F(“Failed to read from DHT sensor!”));
return;
}

Serial.print(F(“8 Frame Roof Temp: “));
Serial.print(t);
Serial.print(F(“°C   “));
Serial.print(F(“8 Frame Roof Humidity: “));
Serial.print(h);
Serial.print(F(“%   “));
Serial. print(‘\n’);

Serial.print(“Battery Level: “);
Serial.print(batteryLevel);
Serial.println (” %”);

//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;

// Your Domain name with URL path or IP address with path
http.begin(serverName);

// Specify content-type header
http.addHeader(“Content-Type”, “application/x-www-form-urlencoded”);

// Prepare your HTTP POST request data
String httpRequestData = “api_key=” + apiKeyValue + “&value1=” + String(dht.readTemperature())
+ “&value2=” + String(dht.readHumidity()) + “&value3=” + String(sensors.getTempC(sensor2)) + “&value4=” + String(scale.get_units(), 1) + “&value5=” + String(batteryLevel()) +””;
Serial.print(“httpRequestData: “);
Serial.println(httpRequestData);

// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);

// If you need an HTTP request with a content type: text/plain
//http.addHeader(“Content-Type”, “text/plain”);
//int httpResponseCode = http.POST(“Hello, World!”);

// If you need an HTTP request with a content type: application/json, use the following:
//http.addHeader(“Content-Type”, “application/json”);
//int httpResponseCode = http.POST(“{\”value1\”:\”19\”,\”value2\”:\”67\”,\”value3\”:\”78\”}”);

if (httpResponseCode>0) {
Serial.print(“HTTP Response code: “);
Serial.println(httpResponseCode);
}
else {
Serial.print(“Error code: “);
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println(“WiFi Disconnected”);
}

Serial.println(“Going to sleep now”);
esp_deep_sleep_start();
}


your code here

1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
In the following line, you have bateryLevel() 

+ “&value2=” + String(dht.readHumidity()) + “&value3=” + String(sensors.getTempC(sensor2)) + “&value4=” + String(scale.get_units(), 1) + “&value5=” + String(batteryLevel()) +””;

And it should be batteryLevel without the (), otherwise it would be a function.

+ “&value2=” + String(dht.readHumidity()) + “&value3=” + String(sensors.getTempC(sensor2)) + “&value4=” + String(scale.get_units(), 1) + “&value5=” + String(batteryLevel) +””;

I hope this helps.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.