Compare commits
2 commits
2c3df9d549
...
fbd5edd62b
Author | SHA1 | Date | |
---|---|---|---|
Sergio Pernas | fbd5edd62b | ||
Sergio Pernas | f45f27b254 |
|
@ -1,76 +1,76 @@
|
|||
int inData;
|
||||
const char* valueSensor;
|
||||
const byte devID = 0x01;
|
||||
int errCode;
|
||||
char sendData[3];
|
||||
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
// Pin donde se conecta el bus 1-Wire
|
||||
const int pinDatosDQ = 2;
|
||||
|
||||
// Instancia a las clases OneWire y DallasTemperature
|
||||
OneWire oneWireObjeto(pinDatosDQ);
|
||||
DallasTemperature sensorDS18B20(&oneWireObjeto);
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
||||
char senType;
|
||||
char senValue;
|
||||
char senUnit;
|
||||
|
||||
} senFrame;
|
||||
// Dispositivo
|
||||
const int devID = 1;
|
||||
char devIDstr[5];
|
||||
int inQuery;
|
||||
|
||||
|
||||
void newFrame (senFrame *pt, char sensor) {
|
||||
|
||||
pt-> senType = "hum";
|
||||
pt-> senValue = "10.5";
|
||||
pt-> senUnit = "%";
|
||||
|
||||
for ( byte i = 0; i < 4; i++) sendData[i] = ( ((byte *)pt)[i] );
|
||||
|
||||
Serial.println (sendData[sensor]);
|
||||
float getData() {
|
||||
|
||||
sensorDS18B20.requestTemperatures();
|
||||
return (sensorDS18B20.getTempCByIndex(0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(14400);
|
||||
Serial.begin(9600);
|
||||
sensorDS18B20.begin();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if ( Serial.available() > 0) {
|
||||
switch (inData) {
|
||||
case devID:
|
||||
newFrame();
|
||||
inQuery = Serial.read();
|
||||
if ( inQuery = devID) {
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*if ( Serial.available() > 0) {
|
||||
inData = Serial.read();
|
||||
|
||||
switch (inData) {
|
||||
case devID:
|
||||
Serial.write("0x01");
|
||||
|
||||
|
||||
Serial.write(itoa(devID, devIDstr, 10));
|
||||
Serial.write(" ");
|
||||
Serial.write("hum");
|
||||
Serial.write("T");
|
||||
//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!
|
||||
|
||||
|
||||
Serial.write(lecturaStr);
|
||||
Serial.write(" ");
|
||||
Serial.write("78");
|
||||
Serial.write(" ");
|
||||
Serial.write("P");
|
||||
Serial.write("C");
|
||||
Serial.write(" ");
|
||||
Serial.write("99");
|
||||
Serial.write(" ");
|
||||
Serial.write("pre");
|
||||
Serial.write(" ");
|
||||
Serial.write("100");
|
||||
Serial.write(" ");
|
||||
Serial.write("Hpa");
|
||||
Serial.write(" ");
|
||||
Serial.write("98");
|
||||
Serial.write(" ");
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} */
|
||||
|
||||
delay(1500);
|
||||
|
||||
}
|
||||
|
|
1
0x01-temperatura/config.ino
Normal file
1
0x01-temperatura/config.ino
Normal file
|
@ -0,0 +1 @@
|
|||
|
30
0x02-turbidez/0x02-turbidez.ino
Normal file
30
0x02-turbidez/0x02-turbidez.ino
Normal file
|
@ -0,0 +1,30 @@
|
|||
int inData;
|
||||
const char* valueSensor;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
if ( Serial.available() > 0) {
|
||||
inData = Serial.read();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue