This commit is contained in:
Sergio Pernas 2022-04-05 18:42:54 -03:00
parent 0d80d649b3
commit b3617f831a
3 changed files with 44 additions and 32 deletions

View file

@ -42,22 +42,16 @@ void loop() {
if ( Serial.available() > 0) {
inQuery = Serial.read();
if ( inQuery = devID) {
if ( inQuery == devID) {
Serial.write(itoa(devID, devIDstr, 10));
Serial.write(" ");
Serial.write("T");
//Serial.write(" ");
Serial.write(" ");
float lectura = getData();
char lecturaStr[8]; // Buffer big enough for 7-character float
dtostrf(lectura, 6, 2, lecturaStr); // Leave room for too large numbers!
char lecturaStr[6]; // Buffer big enough for 7-character float
dtostrf(getData(), 2, 4, lecturaStr); // Leave room for too large numbers!
Serial.write(lecturaStr);
@ -71,6 +65,4 @@ void loop() {
}
delay(1500);
}

View file

@ -1,30 +1,50 @@
int inData;
const char* valueSensor;
// Dispositivo
const int devID = 2;
char devIDstr[5];
int inQuery;
double getData() {
int sensorValue = analogRead(A2);
return (sensorValue * (5.0 / 1024.0));
}
void setup() {
Serial.begin(9600);
}
void loop() {
void loop() {
if ( Serial.available() > 0) {
inData = Serial.read();
inQuery = Serial.read();
if ( inQuery == devID) {
Serial.write(itoa(devID, devIDstr, 10));
Serial.write(" ");
Serial.write("Tur");
Serial.write(" ");
char lecturaStr[6]; // Buffer big enough for 7-character float
dtostrf(getData(), 2, 4, lecturaStr); // Leave room for too large numbers!
Serial.write(lecturaStr);
Serial.write(" ");
Serial.write("TSS");
Serial.write(" ");
Serial.write("99");
switch (inData) {
case 2:
Serial.print(2);
Serial.print(" ");
Serial.print("hum");
Serial.print(" ");
Serial.print("78");
Serial.print(" ");
Serial.print("P");
Serial.print(" ");
Serial.print("99");
Serial.print(" ");
break;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9 KiB