I have been banging my head against this problem for a week. I need help!
I am able to get the following weight from an avery scale and put it into a char array. but i want to push the data through a pushingbox api which is sent as a string. I cant for the life of me figure out the proper way to get this data formatted correctly so that it populates . Warning i'm a newb at coding so graphic content below!! Any suggestions on what im doing inefficient and wrong would be helpful.
the current output of this is 0.0000 no matter what the scale reads.
I know the scale reads the following: "####.#" in terms of digits
#include "ESP8266WiFi.h"
const char WEBSITE[] = "api.pushingbox.com"; //pushingbox API server
const String devid = "device id"; //device ID from Pushingbox
const char* MY_SSID = "ssid";
const char* MY_PWD = "password";
char receivedChar1[16]={'\0'};
char pWeight[6]={'\0'};
char cWeight[6]={'\0'};
float Weight = 0.0;
int Cycles = 0;
boolean newData = false;
boolean Datasend = false;
void setup()
{
Serial.begin(9600, SERIAL_7E1);
WiFi.begin(MY_SSID, MY_PWD);
while (WiFi.status() != WL_CONNECTED) //not connected,..waiting to connect
{
delay(1000);
}
}
void loop()
{
Serial.write(0x57);
Serial.write(0x0D);
recvOneChar();
showNewData();
if (Datasend == true)
{
WiFiClient client; //Instantiate WiFi object
//Start or API service using our WiFi Client through PushingBox
if (client.connect(WEBSITE, 80))
{
//Serial.println("Im printing data: ");
// Serial.print(counter);
client.print("GET /pushingbox?devid=" + devid
+ "&Weight=" + Weight
+ "&Store=9048"
);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(WEBSITE);
client.println("User-Agent: ESP8266/1.0");
client.println("Connection: close");
client.println();
delay(10000);
} else {
//Serial.println("Connection Failed");
}
Datasend = false;
client.stop();
client.flush();
}
}
void recvOneChar()
{
if (Serial.available() > 0)
{
for(int i=0;i<6;i++){pWeight[i]=cWeight[i];}
for(int i=0;i<16;i++)
{
receivedChar1[i] = Serial.read();
if( i >=3 and i<=7){
cWeight[(i-3)]= receivedChar1[i];
}
}
newData = true;
}
}
void showNewData() {
if (newData == true and strcmp(cWeight, " 0.0")!=0) {
if (strcmp(cWeight, pWeight)==0){
Cycles=Cycles+1;
Datasend = false;
} else {
Datasend = false;
Cycles = 0;
}
if (Cycles ==5)
{
Weight = atof(cWeight);
Datasend = true;
newData = false;
}
}
}