Image

Image

Search This Blog

Wednesday, February 03, 2021

ESP Scale pushing to server

 include "HX711.h"

#include "ESP8266WiFi.h"

#include "EEPROM.h"

#include "ESP8266httpUpdate.h"


#define upd_version "6a"

#define upd_reboot true

#define upd_server "123.45.67.89"

#define upd_file "/update/index.php"


const int LOADCELL_DOUT_PIN = D4;

const int LOADCELL_SCK_PIN = D3;


int CalEepromAdress = 101;

int TarEepromAdress = 111;

int DevEepromAdress = 121;


float calibrationValue = 442.06;// See ScaleCalibrate.ino for this. override by EEPROM

float tareValue = 472; // override by EEPROM

String thisScale = "LC000"; // override by EEPROM


char server[] = "123.45.67.90";

String uploadfile = "process.php";

String postVariable = "data=";

const char* ssid = "MyWiFi";

const char* password = "MyP@ssword";


HX711 scale;

WiFiClient client;

ADC_MODE(ADC_VCC);


void setup() {

//  Serial.begin(115200);

 

  EEPROM.begin(512);

  EEPROM.get(CalEepromAdress, calibrationValue);

  EEPROM.get(TarEepromAdress, tareValue);

  EEPROM.get(DevEepromAdress, thisScale);

  EEPROM.end();

 

  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  scale.set_scale(calibrationValue); 

  

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

   delay(200);

  }


  ESPhttpUpdate.rebootOnUpdate(upd_reboot);

  t_httpUpdate_return ret = ESPhttpUpdate.update(upd_server, 80, upd_file, upd_version);


}


void loop() {

  String postData = postVariable + thisScale + "," + ESP.getVcc() + "," + (scale.get_units(10) - tareValue) + "," + upd_version;


  if (client.connect(server, 80)) {

    client.print("POST /");

    client.print(uploadfile);

    client.println(" HTTP/1.1");

    client.print("Host: ");

    client.println (server);

    client.println("Content-Type: application/x-www-form-urlencoded");

    client.print("Content-Length: ");

    client.println(postData.length());

    client.println();

    client.print(postData);

 }

  if (client.connected()) {

      client.stop();

  }

  scale.power_down();

  ESP.deepSleep(300e6);

}

No comments:

Post a Comment

Blog Archive