Hardware:
Adafruit Feather HUZZAH with ESP32
HX711 breakout board with load sensors
Blynk Library 1.0.1
Problem: I have a sketch to upload the weight from a scale to Blynk. I had it working with the Legacy Blynk. I created the Template and device in blynk.cloud. The simplified sketch shown here connects to wifi, uploads to Blynk, disconnects, then goes to sleep for 58 minutes. (The more complex version uses NPT for time and an EP Display.) When the sketch runs, it connects to Blynk. While connected for the short time, my Blynk console shows that the device is connected. However the datastream is not updated with the weight. Can someone take a look to see if I’ve made a mistake in my sketch code?
Update:
So I just realized that the weight IS displaying on the Blynk App (New)!!! That’s great!!
But it still doesn’t display on the web Blynk Console (using Apple Safari) on the dashboard for the device. Any ideas why that might be?
-Newby
Code:
//------------------ BLYNK INFO --------------------------------//
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
char auth[] = "";
#define BLYNK_FIRMWARE_VERSION "0.1.0"
//---------------- LIBRARIES ------------------------------------------//
#include "HX711.h" // HX711 connects controller to loadcell
#include <WiFi.h> // Library to connect ESP32 to WiFi. Includes WiFiUDP
#include "driver/adc.h" // Needed to power down ADC
#include <esp_wifi.h> // Needed to turn off WiFi radio
#include <esp_bt.h> // Needed to turn off BT radio
#include <BlynkSimpleEsp32.h> //Library for uploading data to to Blynk
//-------------- DEFINE TIMERS --------------------------------------------//
#define DEEP_SLEEP_DAY 58 // # minutes for Deep Sleep during day
#define uS_TO_MIN_FACTOR 60000000ULL // Conversion factor for micro seconds to minutes (deep sleep function uses micro seconds)
//------------- HX711 LOADCELL AMPLIFIER BOARD INFO ----------------------//
//Define HX711 load sensor interface pins
#define DOUT 26 //A0 on ESP32
#define CLK 25 //A1 on ESP32
HX711 scale;
float weight;
const long loadcell_offset = 379285; // by calibration
float calibration_factor = 138.50; // by calibration
// ----------------- WiFi INFO ------------------------------------------//
const char *ssid = "ssid name";
const char *password = "ssid password";
//===================================================================//
// SETUP
//===================================================================//
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println();
setCpuFrequencyMhz(80);
Serial.println("CPU Frequency set to 80 Mhz");
adc_power_on();
Serial.println("ADC power ON");
//----------Initialize and Read Scale---------------------------------//
scale.begin(DOUT, CLK);
scale.set_scale(calibration_factor);
scale.set_offset(loadcell_offset);
Serial.println("Taking 100 weight measurments and will use last one ...");
weight = scale.get_units(100);
Serial.print("Weight: ");
Serial.print(weight, 1); //number indicates # of decimal places
Serial.println(" g ");
//------ Connect to WiFi and Blynk ---------------------------------------------//
WiFi.persistent( false );
delay( 1000 );
WiFi.mode(WIFI_STA);
Serial.print("WiFi on and connecting ...");
WiFi.begin(ssid, password);
// Keep track of when we started our attempt to get a WiFi connection
unsigned long startAttemptTime = millis();
// Keep looping while we're not connected for 10 sec (10,000 millisec)
while (WiFi.status() != WL_CONNECTED &&
millis() - startAttemptTime < 10000) {
delay(10);
}
// If not connected, serial print notification and move on.
if (WiFi.status() != WL_CONNECTED) {
Serial.println("FAILED WiFi CONNECTION");
}
// If connection successful, show IP address and update BLYNK.
else {
Serial.println();
Serial.print("Connected to ");
Serial.println(WiFi.SSID()); // Tell us what network is connected
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address to serial monitor
Serial.print("RSSI: ");
Serial.println(WiFi.RSSI());
delay(1000);
Serial.println("Connecting to Blynk...");
Blynk.config(auth); // in place of Blynk.begin(auth, ssid, pass);
Blynk.connect(2000);
if (Blynk.connected() == true ) {
Serial.println("Blynk connected");
delay(500);
Blynk.virtualWrite(V0, weight);
Blynk.run();
Serial.println("Blynk updated");
Blynk.disconnect();
Serial.println("Blynk disconnected");
}
else {
Serial.println("Blynk Connection Failed");
}
}
//----- Disonnect from Wifi -------------------------------------------------------//
WiFi.disconnect(true);
delay(1);
WiFi.mode(WIFI_OFF);
Serial.println("WiFi off");
//--------- Preparation for Deep Sleep ------------------------------------------------//
scale.power_down(); // put the ADC in sleep mode
Serial.println("Scale ADC in sleep mode");
adc_power_off();
Serial.println("ADC powered down");
esp_wifi_stop();
Serial.println("WiFi radio powered down");
esp_bt_controller_disable();
Serial.println("BT radio powered down");
//--------- Go into Deep Sleep ---------------------------------------------------------//
esp_sleep_enable_timer_wakeup(DEEP_SLEEP_DAY * uS_TO_MIN_FACTOR);
Serial.print("Going into deep sleep for ");
Serial.print(DEEP_SLEEP_DAY);
Serial.println(" minutes");
Serial.println();
esp_deep_sleep_start();
}
void loop() {}