The Bridge/bridge exemple is working
But why this is not working ? the sensor gives me data, they are readable via console.. But when I access the URL http://arduino.local/arduino/pm/ nothings is present.
#include <Console.h>
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
YunServer server;
String startString;
long hits = 0;
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
void setup() {
Serial.begin(9600);
Bridge.begin();
Console.begin();
Console.println("PM Sensor test");
pinMode(8,INPUT);
starttime = millis();
server.listenOnLocalhost();
server.begin();
// get the time that this sketch started:
Process startTime;
startTime.runShellCommand("date");
while(startTime.available()) {
char c = startTime.read();
startString += c;
}
}
void loop() {
float lastRatio[5];
YunClient client = server.accept();
duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;
if ((millis()-starttime) > sampletime_ms)
{
ratio = lowpulseoccupancy/(sampletime_ms*10.0); // Integer percentage 0=>100
concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
Console.print(lowpulseoccupancy);
Console.print(",");
Console.print(ratio);
Console.print(",");
Console.println(concentration);
lowpulseoccupancy = 0;
starttime = millis();
}
if (client) {
String command = client.readString();
command.trim(); //kill whitespace
Console.println(command);
if (command == "pm") {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("Let's Go");
lastRatio[hits %5 ] = ratio;
for(int i=0;i<5 ;i++ )
client.print(lastRatio[i]);
client.print(";");
}
hits++;
}
}