add mDNS service, add tare button, tare procedure improved
This commit is contained in:
parent
6dcdf52955
commit
b8964c87d1
167
CG_scale.ino
167
CG_scale.ino
@ -4,7 +4,7 @@
|
|||||||
(c) 2019 by M. Lehmann
|
(c) 2019 by M. Lehmann
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
#define CGSCALE_VERSION "1.0.63"
|
#define CGSCALE_VERSION "1.0.65"
|
||||||
/*
|
/*
|
||||||
|
|
||||||
******************************************************************
|
******************************************************************
|
||||||
@ -56,8 +56,8 @@
|
|||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiClient.h>
|
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -268,6 +268,31 @@ bool runAutoCalibrate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// check if a loadcell has error
|
||||||
|
bool getLoadcellError(){
|
||||||
|
bool err = false;
|
||||||
|
|
||||||
|
if (LoadCell_1.getTareTimeoutFlag()) {
|
||||||
|
errMsg[++errMsgCnt] = "ERROR: Timeout TARE Lc1\n";
|
||||||
|
err = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LoadCell_2.getTareTimeoutFlag()) {
|
||||||
|
errMsg[++errMsgCnt] = "ERROR: Timeout TARE Lc2\n";
|
||||||
|
err = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nLoadcells > 2) {
|
||||||
|
if (LoadCell_3.getTareTimeoutFlag()) {
|
||||||
|
errMsg[++errMsgCnt] = "ERROR: Timeout TARE Lc3\n";
|
||||||
|
err = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
// init serial
|
// init serial
|
||||||
@ -381,83 +406,37 @@ void setup() {
|
|||||||
|
|
||||||
// init & tare Loadcells
|
// init & tare Loadcells
|
||||||
LoadCell_1.begin();
|
LoadCell_1.begin();
|
||||||
LoadCell_1.start(STABILISINGTIME);
|
//LoadCell_1.start(STABILISINGTIME);
|
||||||
LoadCell_2.begin();
|
|
||||||
LoadCell_2.start(STABILISINGTIME);
|
|
||||||
|
|
||||||
if (LoadCell_1.getTareTimeoutFlag()) {
|
|
||||||
errMsg[++errMsgCnt] = "ERROR: Timeout TARE Lc1\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LoadCell_1.setCalFactor(calFactorLoadcell1);
|
LoadCell_1.setCalFactor(calFactorLoadcell1);
|
||||||
}
|
|
||||||
|
|
||||||
if (LoadCell_2.getTareTimeoutFlag()) {
|
LoadCell_2.begin();
|
||||||
errMsg[++errMsgCnt] = "ERROR: Timeout TARE Lc2\n";
|
//LoadCell_2.start(STABILISINGTIME);
|
||||||
}
|
|
||||||
else {
|
|
||||||
LoadCell_2.setCalFactor(calFactorLoadcell2);
|
LoadCell_2.setCalFactor(calFactorLoadcell2);
|
||||||
}
|
|
||||||
|
|
||||||
if (nLoadcells > 2) {
|
if (nLoadcells > 2) {
|
||||||
LoadCell_3.begin();
|
LoadCell_3.begin();
|
||||||
LoadCell_3.start(STABILISINGTIME);
|
//LoadCell_3.start(STABILISINGTIME);
|
||||||
|
|
||||||
if (LoadCell_3.getTareTimeoutFlag()) {
|
|
||||||
errMsg[++errMsgCnt] = "ERROR: Timeout TARE Lc3\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LoadCell_3.setCalFactor(calFactorLoadcell3);
|
LoadCell_3.setCalFactor(calFactorLoadcell3);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
// stabilize scale values
|
||||||
// init Loadcells
|
long stabilisingtime = millis() + STABILISINGTIME;
|
||||||
LoadCell_1.begin();
|
while(millis() < stabilisingtime) {
|
||||||
LoadCell_2.begin();
|
LoadCell_1.update();
|
||||||
|
LoadCell_2.update();
|
||||||
if (nLoadcells > 2) {
|
if (nLoadcells > 2) {
|
||||||
LoadCell_3.begin();
|
LoadCell_3.update();
|
||||||
}
|
|
||||||
|
|
||||||
// tare
|
|
||||||
byte loadcell_1_rdy = 0;
|
|
||||||
byte loadcell_2_rdy = 0;
|
|
||||||
byte loadcell_3_rdy = 0;
|
|
||||||
lastTimeLoadcell = millis();
|
|
||||||
|
|
||||||
while ((loadcell_1_rdy + loadcell_2_rdy + loadcell_3_rdy) < 3) {
|
|
||||||
loadcell_1_rdy = LoadCell_1.startMultiple(STABILISINGTIME);
|
|
||||||
loadcell_2_rdy = LoadCell_2.startMultiple(STABILISINGTIME);
|
|
||||||
if (nLoadcells == 3) {
|
|
||||||
loadcell_3_rdy = LoadCell_3.startMultiple(STABILISINGTIME);
|
|
||||||
} else {
|
|
||||||
loadcell_3_rdy = 1;
|
|
||||||
}
|
|
||||||
// timeout
|
|
||||||
if ((millis() - lastTimeLoadcell) > TARE_TIMEOUT) {
|
|
||||||
errMsg[++errMsgCnt] = "ERROR: Timeout TARE\n";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check loadcells if error
|
LoadCell_1.tare();
|
||||||
if (!loadcell_1_rdy) {
|
LoadCell_2.tare();
|
||||||
errMsg[++errMsgCnt] = "ERROR: Loadcell 1 not ready\n";
|
|
||||||
}
|
|
||||||
if (!loadcell_2_rdy) {
|
|
||||||
errMsg[++errMsgCnt] = "ERROR: Loadcell 2 not ready\n";
|
|
||||||
}
|
|
||||||
if (!loadcell_3_rdy) {
|
|
||||||
errMsg[++errMsgCnt] = "ERROR: Loadcell 3 not ready\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// set calibration factor
|
|
||||||
LoadCell_1.setCalFactor(calFactorLoadcell1);
|
|
||||||
LoadCell_2.setCalFactor(calFactorLoadcell2);
|
|
||||||
if (nLoadcells > 2) {
|
if (nLoadcells > 2) {
|
||||||
LoadCell_3.setCalFactor(calFactorLoadcell3);
|
LoadCell_3.tare();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
getLoadcellError();
|
||||||
|
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
@ -487,7 +466,7 @@ void setup() {
|
|||||||
oledDisplay.setCursor(0, 64);
|
oledDisplay.setCursor(0, 64);
|
||||||
oledDisplay.print(WiFi.localIP());
|
oledDisplay.print(WiFi.localIP());
|
||||||
} while ( oledDisplay.nextPage() );
|
} while ( oledDisplay.nextPage() );
|
||||||
//delay(5000);
|
delay(2000);
|
||||||
} else {
|
} else {
|
||||||
// if WiFi not connected, switch to access point mode
|
// if WiFi not connected, switch to access point mode
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
@ -495,9 +474,20 @@ void setup() {
|
|||||||
WiFi.softAP(ssid_AP, password_AP);
|
WiFi.softAP(ssid_AP, password_AP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// init mDNS
|
||||||
|
String hostName = ssid_AP;
|
||||||
|
hostName.replace(" ", "");
|
||||||
|
hostName.toLowerCase();
|
||||||
|
char hostString[32];
|
||||||
|
hostName.toCharArray(hostString, 32);
|
||||||
|
MDNS.begin(hostString);
|
||||||
|
|
||||||
// init webserver
|
// init webserver
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
||||||
|
// Add service to MDNS-SD
|
||||||
|
MDNS.addService("http", "tcp", 80);
|
||||||
|
|
||||||
// When the client requests data
|
// When the client requests data
|
||||||
server.on("/getHead", getHead);
|
server.on("/getHead", getHead);
|
||||||
server.on("/getValue", getValue);
|
server.on("/getValue", getValue);
|
||||||
@ -506,6 +496,7 @@ void setup() {
|
|||||||
server.on("/getWiFiNetworks", getWiFiNetworks);
|
server.on("/getWiFiNetworks", getWiFiNetworks);
|
||||||
server.on("/saveParameter", saveParameter);
|
server.on("/saveParameter", saveParameter);
|
||||||
server.on("/autoCalibrate", autoCalibrate);
|
server.on("/autoCalibrate", autoCalibrate);
|
||||||
|
server.on("/tare", runTare);
|
||||||
server.on("/saveModel", saveModel);
|
server.on("/saveModel", saveModel);
|
||||||
server.on("/openModel", openModel);
|
server.on("/openModel", openModel);
|
||||||
server.on("/deleteModel", deleteModel);
|
server.on("/deleteModel", deleteModel);
|
||||||
@ -520,17 +511,29 @@ void setup() {
|
|||||||
if (!handleFileRead(server.uri()))
|
if (!handleFileRead(server.uri()))
|
||||||
server.send(404, "text/plain", "404: Not Found");
|
server.send(404, "text/plain", "404: Not Found");
|
||||||
});
|
});
|
||||||
#endif
|
|
||||||
|
|
||||||
// stabilize scale values
|
Serial.println("Sending mDNS query");
|
||||||
for (int i = 0; i <= 15; i++) {
|
int n = MDNS.queryService("esp", "tcp"); // Send out query for esp tcp services
|
||||||
LoadCell_1.update();
|
Serial.println("mDNS query done");
|
||||||
LoadCell_2.update();
|
if (n == 0) {
|
||||||
if (nLoadcells > 2) {
|
Serial.println("no services found");
|
||||||
LoadCell_3.update();
|
} else {
|
||||||
}
|
Serial.print(n);
|
||||||
delay(200);
|
Serial.println(" service(s) found");
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
// Print details for each service found
|
||||||
|
Serial.print(i + 1);
|
||||||
|
Serial.print(": ");
|
||||||
|
Serial.print(MDNS.hostname(i));
|
||||||
|
Serial.print(" (");
|
||||||
|
Serial.print(MDNS.IP(i));
|
||||||
|
Serial.print(":");
|
||||||
|
Serial.print(MDNS.port(i));
|
||||||
|
Serial.println(")");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -961,6 +964,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
|
MDNS.update();
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1167,6 +1171,21 @@ void autoCalibrate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// tare cg scale
|
||||||
|
void runTare() {
|
||||||
|
LoadCell_1.tare();
|
||||||
|
LoadCell_2.tare();
|
||||||
|
if (nLoadcells > 2) {
|
||||||
|
LoadCell_3.tare();
|
||||||
|
}
|
||||||
|
if (!getLoadcellError()){
|
||||||
|
server.send(200, "text/plain", "tare completed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
server.send(404, "text/plain", "404: tare failed !");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// save new model
|
// save new model
|
||||||
void saveModel() {
|
void saveModel() {
|
||||||
if (server.hasArg("modelname")) {
|
if (server.hasArg("modelname")) {
|
||||||
|
0
data/airplane.png
Normal file → Executable file
0
data/airplane.png
Normal file → Executable file
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
0
data/home.png
Normal file → Executable file
0
data/home.png
Normal file → Executable file
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
Binary file not shown.
0
data/settings.png
Normal file → Executable file
0
data/settings.png
Normal file → Executable file
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
@ -51,14 +51,14 @@ CG scale with 3 Loadcells:
|
|||||||
#define PIN_LOADCELL2_DOUT D2
|
#define PIN_LOADCELL2_DOUT D2
|
||||||
#define PIN_LOADCELL2_PD_SCK D1
|
#define PIN_LOADCELL2_PD_SCK D1
|
||||||
|
|
||||||
#define PIN_LOADCELL3_DOUT D8
|
#define PIN_LOADCELL3_DOUT D0
|
||||||
#define PIN_LOADCELL3_PD_SCK D7
|
#define PIN_LOADCELL3_PD_SCK D7
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// **** Measurement settings ****
|
// **** Measurement settings ****
|
||||||
|
|
||||||
#define STABILISINGTIME 2000 // ms
|
#define STABILISINGTIME 3000 // ms
|
||||||
|
|
||||||
#define UPDATE_INTERVAL_OLED_MENU 500 // ms
|
#define UPDATE_INTERVAL_OLED_MENU 500 // ms
|
||||||
#define UPDATE_INTERVAL_LOADCELL 100 // ms
|
#define UPDATE_INTERVAL_LOADCELL 100 // ms
|
||||||
@ -135,7 +135,7 @@ U8G2_SH1106_128X64_NONAME_1_HW_I2C oledDisplay(U8G2_R0, /* reset=*/ U8X8_PIN_NON
|
|||||||
// Access point mode: create own network
|
// Access point mode: create own network
|
||||||
#define SSID_AP "CG scale"
|
#define SSID_AP "CG scale"
|
||||||
#define PASSWORD_AP ""
|
#define PASSWORD_AP ""
|
||||||
const char ip[4] = {1,1,1,1}; // default IP address
|
const char ip[4] = {1,2,3,4}; // default IP address
|
||||||
|
|
||||||
|
|
||||||
// **** Model memory settings ****
|
// **** Model memory settings ****
|
||||||
|
Loading…
x
Reference in New Issue
Block a user