Question: PLEASE HELP, the code is not complete. I am using this code to get data transmitted from a load cell wirelessly from an arduino board
PLEASE HELP, the code is not complete. I am using this code to get data transmitted from a load cell wirelessly from an arduino board to a webserver. I have gotten to the point where I'm able to open the webserver but nothing shows up in it. I need the data collected from the serial monitor to show up on the webserver. PLEASE HELP
// Load Wi-Fi library #include
// Replace with your network credentials const char* ssid = "wifi net work ssid"; const char* password = "wifi network password";
// Set web server port number to 80 WiFiServer server(80);
// Variable to store the HTTP request String header;
// Auxiliar variables to store the current output state String output5State = "off"; String output4State = "off";
// Assign output variables to pins const int output5 = D7; const int output4 = D6;
// Current time unsigned long currentTime = millis(); // Previous time unsigned long previousTime = 0; // Define timeout time in milliseconds (example: 2000ms = 2s) const long timeoutTime = 2000;
#include "HX711.h"
#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch //int sensorValue=analogRead(A0) #define LOADCELL_DOUT_PIN D7 #define LOADCELL_SCK_PIN D6
HX711 scale;
void setup() { Serial.begin(115200); // Connect to Wi-Fi network with SSID and password Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } // Print local IP address and start web server Serial.println(""); Serial.println("WiFi connected."); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); Serial.println("Weight of the barrel"); 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.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
}
void loop() { WiFiClient client = server.available(); // Listen for incoming clients if (client) { // If a new client connects, Serial.println("New Client."); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client currentTime = millis(); previousTime = currentTime; while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected currentTime = millis(); if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor header += c; if (c == ' ') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); //Start using load cell if(scale.get_units()>0.5&& scale.get_units()<1.0) { Serial.print("Reading: "); Serial.print(scale.get_units(), 1); //scale.get_units() returns a float Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor Serial.println(); // Display the HTML web page client.println(""); client.println("
"); client.println(""); // Web Page Heading client.println("Weight of the barrel
"); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
