Weigh scale project

Continuing the discussion from No values seen in IoT cloud:

Hi, similar problem, values not updating in the web or app dashboard. Everything else works fine. The serial monitor weighs and displays the reading and connections, the SMS function works but the dashboard is showing 0. Have declared the variables globally as suggested, except for the < int upperlimit >, which I think, shouldn't matter. Can someone please help me as to where I am going wrong> Here's the code:

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Weightscale"
  https://create.arduino.cc/cloud/things/f6787cc2-8e93-4138-89e3-e9f23dd83166 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float mass;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <ESP8266WiFi.h>
#include <HX711.h>


const char* ssid ="Hidden";
const char* password = "Hidden";
const char* host = "maker.ifttt.com";

HX711 scale;
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;


//define the parameters for the IFTTT

#define HOSTIFTTT "maker.ifttt.com"
#define EVENTO "Weightscale"
#define IFTTTKEY "9X9uqsXq6O5F8XJU_49NW"

WiFiClient client;

boolean alreadyRun = false; 
float reading;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  
  
  //Serial.begin(38400);
  //delay(5000);
  Serial.println("HX711 Demo");

  Serial.println("Initializing the scale");

  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  Serial.println("Before setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());			// print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));  	// print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight (not set yet)

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);	// print the average of 5 readings from the ADC minus tare weight (not set) divided
						// by the SCALE parameter (not set yet)

  scale.set_scale(-104625.f);                      // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();				        // reset the scale to 0

  Serial.println("After setting up the scale:");

  Serial.print("read: \t\t");
  Serial.println(scale.read());                 // print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));       // print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight, set with tare()

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);        // print the average of 5 readings from the ADC minus tare weight, divided
						// by the SCALE parameter set with set_scale

  Serial.println("Readings:");
  
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  Serial.print("The weight in kg is:\t");
  reading = (scale.get_units(5));   // Assign Weight to reading
  Serial.println(reading);

  int upperLimit = 2; 
  
  if(reading > upperLimit && alreadyRun == false)
  {
    sendSMS();
    alreadyRun = true;
  }
  
  else {
        
        Serial.println("Still running loop()");
        delay(1000);
        
        if(reading < upperLimit && alreadyRun == true)
       {
        alreadyRun = false;
       }
      
      }

}

void sendSMS()
{
    Serial.println("Initiating to send SMS");
    WiFi.begin(ssid, password);
    Serial.println(" ");
    Serial.print("Waiting to connect to WiFi....");
    while (WiFi.status() != WL_CONNECTED)
    {
    delay(500);
    Serial.print(".");
    }
    Serial.print("");
    Serial.print("Connected to ");
    Serial.print(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
    delay(1000);
   
    if (client.connected())
    {
      client.stop();
    }

  client.flush();
    if (client.connect(host,80)) 
    {
    Serial.println("Connected");
    // build the HTTP request

    String toSend = "GET /trigger/";
    toSend += EVENTO;
    toSend += "/with/key/";
    toSend += IFTTTKEY;
    toSend += "?value1=";
    toSend += reading;
    toSend += " HTTP/1.1\r\n";
    toSend += "Host: ";
    toSend += HOSTIFTTT;
    toSend += "\r\n";
    toSend += "Connection: close\r\n\r\n";
    client.print(toSend);
    delay(1000);
  
    Serial.print("SMS Sent");
    delay(1000);
    }
  
    client.flush();
    client.stop();  
 
  
  
}


Here's the output:

Connected to "saumabha_cable"
The weight in kg is: -0.00
Still running loop()
The weight in kg is: -0.00
Still running loop()
The weight in kg is: -0.00
Still running loop()
The weight in kg is: -0.00
Still running loop()
The weight in kg is: -0.00
Still running loop()
The weight in kg is: -0.00
Still running loop()
The weight in kg is: -0.08
Still running loop()
The weight in kg is: 0.00
Still running loop()
Connected to Arduino IoT Cloud
Thing ID: f6787cc2-8e93-4138-89e3-e9f23dd83166
The weight in kg is: -0.00
Still running loop()
The weight in kg is: -0.00
Still running loop()
The weight in kg is: -0.00
Still running loop()
The weight in kg is: -0.00
Still running loop()
The weight in kg is: 0.00
Still running loop()
The weight in kg is: -0.00

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.