Hello
a few weeks ago i recived my first arduino EtherTen.
this is a arduino uno with Ethernet.
I want to make a weather station.
What i did:
- Add all components to the arduino
- Let the code write all variable to the serial console
- add networking
- let the arduino call a http string with static value
So far everything worked
when i want to combine some variable to a link the result is a blank line
what do i wrong?
the intresting part of the code
String RFall = String(weather.total_rainfall(), DEC);
HString = "/send?{%22action%22:%22control%22,%22code%22:{%22device%22:%22RainMesurement%22,%22values%22:{%22label%22:%22" + RFall + "%22,%22color%22:%22black%22}}}";
Serial.println(HString);
Pilight(HString);
the full part of the code
/*
VLD Weather station
25-04-2015
*/
const int Ver = 5;
#include <TimerOne.h>
#include <Weather.h>
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
// pin assignment
const int RainPin = 6; // pin for raindrop sensor
const int TempPin = 5; // pin for onewire devices
const int ledPin = 13; // Pin for onboard LED
/*weather libarie has fixed pins
RainGauge 2
Anemometer 3
WindVane A3
*/
byte myserver[] = { 172, 16, 20, 134 }; // Pilight server
//default variable
int RainState = 0; // the state of the raindrop sensor
int PRainState = 0; // see if ther is anything changed
#define SERIAL_BAUDRATE 9600
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
}; // IF no onewire device is found use this mac
EthernetClient client;
OneWire ds(TempPin); // Set up DS18B20 sensor
String HString;
void setup() {
Serial.begin(SERIAL_BAUDRATE);
Serial.print("Weatherstation V");
Serial.print(Ver);
Serial.println();
pinMode(RainPin, INPUT);
byte i;
byte dsAddress[8];
weather.initialize();
delay( 500 ); // Give the Ethernet chipset time to fully initialise
ds.reset_search(); // Start the search with the first device
if ( !ds.search(dsAddress) )
{
Serial.println( "none found. Using default MAC address." );
} else {
// Offset array to skip DS18B20 family code, and skip mac[0]
mac[1] = dsAddress[3];
mac[2] = dsAddress[4];
mac[3] = dsAddress[5];
mac[4] = dsAddress[6];
mac[5] = dsAddress[7];
}
Ethernet.begin( mac );
Serial.print( "My IP address: " );
Serial.println( Ethernet.localIP() );
}
void loop() {
//Raindrop sensor
RainState = digitalRead(RainPin); // read the state of the Raindropsensor value:
// check if the Sensor is wet. if it is, the RainState is HIGH:
if (RainState == LOW) {
if (PRainState == 0) { // and it was not raining
HString = "/send?{%22action%22:%22control%22,%22code%22:{%22device%22:%22Rain%22,%22state%22:%22on%22}}";
Pilight(HString); // call pilight function to inform the pilight server about the rain
PRainState=1;
}
}
else {
if (PRainState == 1) {
// turn LED off:
HString = "/send?{%22action%22:%22control%22,%22code%22:{%22device%22:%22Rain%22,%22state%22:%22off%22}}";
Pilight(HString); // call sendRainOn function below when it rains
PRainState=0;
}
}
Serial.println("regenval");
String RFall = String(weather.total_rainfall(), DEC);
if (PRainState == 0) {
HString = "/send?{%22action%22:%22control%22,%22code%22:{%22device%22:%22RainMesurement%22,%22values%22:{%22label%22:%22" + RFall + "%22,%22color%22:%22black%22}}}";
Serial.println(HString);
Pilight(HString);
} else {
HString = "/send?{%22action%22:%22control%22,%22code%22:{%22device%22:%22RainMesurement%22,%22values%22:{%22label%22:%22" + RFall + "%22,%22color%22:%22red%22}}}";
Pilight(HString);
}
String WName = String(weather.wind_direction_name());
HString = "/send?{%22action%22:%22control%22,%22code%22:{%22device%22:%22WindDirection%22,%22values%22:{%22label%22:%22" + WName + "%22,%22color%22:%22black%22}}}";
Pilight(HString);
String WSpeed = String(weather.wind_speed ,DEC);
if (weather.wind_speed < 24) {
HString = "/send?{%22action%22:%22control%22,%22code%22:{%22device%22:%22WindSpeed%22,%22values%22:{%22label%22:%22" + WSpeed + "%22,%22color%22:%22black%22}}}";
Pilight(HString);
} else {
HString = "/send?{%22action%22:%22control%22,%22code%22:{%22device%22:%22WindSpeed%22,%22values%22:{%22label%22:%22" + WSpeed + "%22,%22color%22:%22black%22}}}";
Pilight(HString);
}
// information from the weatherstation
Serial.print("Windrichting: ");
Serial.print(weather.wind_direction_name());
Serial.print(" ( ");
Serial.print(weather.wind_direction_degs());
Serial.print(" )");
Serial.println();
Serial.print("Windkracht: ");
Serial.print(weather.wind_speed);
Serial.print(" KM/H");
Serial.println();
Serial.print("Regenval: ");
Serial.print(weather.total_rainfall());
Serial.print(" mm");
Serial.println();
Serial.print("Regen: ");
Serial.print(PRainState);
Serial.println();
//temperature
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius;
if ( !ds.search(addr)) {
ds.reset_search();
delay(250);
return;
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
type_s = 1;
break;
case 0x28:
type_s = 0;
break;
case 0x22:
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
Serial.println("");
String Adr = String(addr[7], HEX);
Serial.print("Temp" + Adr + " = " + celsius);
Serial.print((char)176);
Serial.println("C");
HString = "/send?{%22action%22:%22control%22,%22code%22:{%22device%22:%22Temp" + Adr + "%22,%22values%22:{%22temperature%22:" + Adr + ",%22color%22:%22black%22}}}";
Pilight(HString);
delay(5000);
}
void Pilight(String HString) //client function to send data to pilight
{
if (client.connect(myserver, 5001)) { //starts client connection, checks for connection
client.print("GET ");
client.print(HString);
client.print(" HTTP/1.0");
client.println(); //end of get request
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
Serial.print(c); //prints byte to serial monitor
}
Serial.println();
client.stop(); //stop client
} :stuck_out_tongue: