Good mornings together.
Oh, ok. I understand. Therefore I post now the two programs which I would like to combine.
The first is the now running program which recheives the data from a logger an pushs them to a MySQL Database:
/*
* Exhibit: weather station
*
* Hardware: Arduino Duemilanove, Ethernet-Shield (Wiznet W5100)
*
* datalogger on serial port (Pin0) with 1200 - unidirectional
* second Serial Port for Debug-Infos-Out on Pin 2/3
* two color LED for status on Pin 6/7
*/
#include <Ethernet.h>
#include <string.h>
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); //for DEBUG
byte mac[] = { 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX }; // myMAC
byte ip[] = { XXX, XXX, XXX, XXX }; // myIP
byte gateway[] = { XXX, XXX, XXX, XXX }; // myGateway
byte subnet[] = { 255, 255, 255, 0 }; // mySubnet
byte server[] = { XXX, XXX, XXX, XXX }; // IP from the MySQL Server with PHP-Skript
Client client(server, 80);
int gnLED = 6; //LED green: programm is waiting, yellow (both colors on) read or write data, red on errors
int rtLED = 7;
char input[50] = ""; // Buffer for incoming data
char current; // Buffer for the current character
int incount = 0; // Counter for the Array
bool lineComplete = false; // Mark if line is complete
unsigned long counter = 1; // Counter how often we recheive data from the logger
unsigned long errorcounter = 1; // counter for connection-errors
unsigned long time; // variables to save the up-time
unsigned long days = 0;
unsigned long hours = 0;
unsigned long minutes = 0;
unsigned long seconds = 0;
char host[] = "www.HOST.de"; // URL of my host
char url[] = "/de/weather.html";
char key[] = "xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx";
char *vel;
char *dir;
char *itemp;
char *atemp;
char c;
void setup() {
pinMode(gnLED, OUTPUT);
pinMode(rtLED, OUTPUT);
digitalWrite(gnLED, HIGH);
digitalWrite(rtLED, LOW);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(1200);
mySerial.begin(9600);
mySerial.println("programm starts... ");
Ethernet.begin(mac, ip, gateway, subnet);
delay(1000);
}
void loop()
{
while ( (Serial.available()) & (incount < 40) & (!lineComplete) )
{
digitalWrite(gnLED, HIGH);
digitalWrite(rtLED, HIGH);
current = Serial.read();
if (current != 13)
{
input[incount] = current;
incount++;
}
else
{
input[incount] = '\0';
lineComplete = true;
}
}
if (lineComplete)
{
mySerial.println("data is:");
input[0]='\ ';
mySerial.println(input);
vel = strtok(input, " ");
mySerial.print("Vel: ");
mySerial.println(vel);
dir = strtok(NULL, " ");
mySerial.print("Dir: ");
mySerial.println(dir);
itemp = strtok(NULL, " ");
mySerial.print("ITemp: ");
mySerial.println(itemp);
atemp = strtok(NULL, " ");
mySerial.print("ATemp: ");
mySerial.println(atemp);
mySerial.print("connecting...");
if (client.connect())
{
mySerial.print("Connection established. Sending Data...");
client.print("GET ");
client.print(url);
client.print("?key=");
client.print(key);
client.print("&temp=");
client.print(atemp);
client.print("&dir=");
client.print(dir);
client.print("&vel=");
client.print(vel);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(host);
client.println();
mySerial.println("Ready!");
Laufzeitausgabe();
digitalWrite(gnLED, HIGH);
digitalWrite(rtLED, LOW);
}
else
{
mySerial.println(" ***** CONNECTION FAILED *****");
mySerial.print("ERROR-Number: ");
mySerial.println(errorcounter);
digitalWrite(gnLED, LOW);
digitalWrite(rtLED, HIGH);
errorcounter++;
Laufzeitausgabe();
}
lineComplete = false;
incount = 0;
client.stop();
strcpy(vel,"");
strcpy(dir,"");
strcpy(itemp,"");
strcpy(atemp,"");
strcpy(input,"");
Serial.flush();
client.flush();
counter++;
}
else if (incount >= 40)
{
mySerial.println("Buffer full!!!");
incount = 0;
lineComplete = false;
digitalWrite(gnLED, LOW);
digitalWrite(rtLED, HIGH);
}
if (client.available())
{
char c = client.read();
mySerial.print(c);
}
}
void Laufzeitausgabe()
{
mySerial.print("Program runs ");
mySerial.print(counter);
mySerial.print(" times and is running since ");
time = millis();
seconds = time / 1000;
minutes = Sekunden / 60;
hours = Minuten / 60;
days = Stunden / 24;
seconds = seconds - (60 * minutes);
minutes = minutesuten - (60 * hours);
hours = hours - (24 * days);
mySerial.print(days);
mySerial.print("days, ");
mySerial.print(hours);
mySerial.print("hours, ");
mySerial.print(minutes);
mySerial.print("minutes and ");
mySerial.print(seconds);
mySerial.println("seconds.");
}
The second is the program prints the data to a website:
/*
* Exhibit: weather station
*
* Hardware: Arduino Duemilanove, Ethernet-Shield (Wiznet W5100)
*
* datalogger on serial port (Pin0) with 1200 - unidirectional
* Data-out
*
*/
#include <Ethernet.h>
byte mac[] = { 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX }; // myMAC
byte ip[] = { XXX, XXX, XXX, XXX }; // myIP
byte gateway[] = { XXX, XXX, XXX, XXX }; // myGateway
byte subnet[] = { 255, 255, 255, 0 }; // mySubnet
Server server(80);
int counter = 0;
char data[50]={""}; // data-array
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(1200);
}
void loop(){
if ( Serial.available() ) {
while (Serial.available() > 0 ) {
data[counter++] = Serial.read();
}
// Serial.println(data);
}
counter = 0;
Client client = server.available();
if (client) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<font color='darkblue' size='5'>Exhibit Weather Station</font>
");
client.println("<font color='blue'>Data from Logger
");
client.println(data);
client.println("
");
client.stop();
}
}
The question now is, how can i combine these sketches. I would like to have all the Serial-Outs form the first program on a website like in the second.
A funktion like this:
Client client(server, 80);
Server server(80);
does not work.
Thank you very much for help!
Poldi