Hi there,
i am working on a project to get weight scale data from a serial port and save it to an online database.
I hav connected an weight scale indicator (industrial) to my Arduino Yun Mini.
What i have reached so far is that the Arduino is checking every 5 seconds if a bit is high in my online database. When it is, the arduino must read the data from the weight scale and should post it (through) a PHP script in my database.
Code:
#include <SoftwareSerial.h>
#include <Bridge.h>
#include <HttpClient.h>
#include <Console.h>
SoftwareSerial mySerial(10,11);
const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
void setup()
{
Bridge.begin();
Serial.begin(9600);
mySerial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void loop() {
HttpClient client;
String clientline;
client.get("http://xxx.xxx.xxx/updateweight.php?eventtype=getStatus&indicator=AYM01");
int _available = client.available();
if (_available> 0) {
clientline = client.readString();
};
clientline.trim();
Serial.println(clientline);
if(clientline=="1"){
Serial.println("posting");
HttpClient clientPost;
String clientlinePost;
String postValue;
String postWeight;
String postByte;
String leesString;
digitalWrite(13, HIGH);
postValue = "http://xxx.xxx.xxx/updateweight.php?eventtype=postValue&indicator=AYM01&weightvalue=";
//mySerial.write('READ');
//mySerial.write(char(13)+char(10));
delay(1000);
while (mySerial.available() > 0) {
//postWeight = mySerial.readString();
// postByte = mySerial.readStringUntil('\r');
// postWeight += postByte;
//postWeight += mySerial.read();
//char c = mySerial.read(); //gets one byte from serial buffer
leesString += mySerial.read(); //makes the string readString
leesString += ',';
}
postValue+=leesString;
clientPost.get(postValue);
int _available = clientPost.available();
if (_available> 0) {
clientlinePost = clientPost.readString();
};
clientlinePost.trim();
//Serial.println(clientlinePost);
if(clientlinePost=="OK"){
clientPost.get("http://xxx.xxx.xxx/updateweight.php?eventtype=setStatus&indicator=AYM01");
digitalWrite(13, LOW);
};
}
Serial.flush();
delay(5000);
}
The string i am getting saved in my DB is:
86,213,90,101,157,191,191,191,191,191,157,163
The weight scale is at 1kg. It is consequent data because when i request new data i get the same string. If i change the weight scale i will get another value.
The numbers cannot be related to the ASCII table. Does anyone has a clue what type of conversion i need in this stage?
I'am really a newby so don't mind kicking my ass