Hi,
I followed instructions on how to read analog input values and post them to a html page:
works fine, but i want to decrease the delay between subsequent accesses to less milliseconds.
I.e., when choosing an update interval of 5ms, the linux is at about 83% usage due to the permanent execution of the bridge.py script (found out via ssh, calling top and seeing bridge.py at the top with 83% cpu usage).
i am not able to achieve shorter times than approx. 240ms for the overall reading of an anlogue value and posting it to linino.
is their any way to accelerate this process?
the used sketch is below
/*
Adapted "Temperature" web interface
Based on http://arduino.cc/en/Tutorial/TemperatureWebPanel
*/
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
// Listen on default port 5555, the webserver on the Yun
// will forward there all the HTTP requests for us.
YunServer server;
unsigned long time;
void setup() {
Serial.begin(9600);
// Bridge startup
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Bridge.begin();
digitalWrite(13, HIGH);
// Listen for incoming connection only from localhost
// (no one from the external network could connect)
server.listenOnLocalhost();
server.begin();
time = millis();
}
void loop() {
// Get clients coming from server
YunClient client = server.accept();
// There is a new client?
if (client) {
// read the command
String command = client.readString();
command.trim(); //kill whitespace
Serial.print("Recognized command: ");
Serial.println(command);
// is "values" command?
if (command == "values") {
int sensorValue = analogRead(A1);
// convert the reading to millivolts:
float voltage = sensorValue * (5000 / 1024);
// print the voltage:
client.print("
Current voltage: ");
client.print(voltage);
client.print("mV.");
unsigned long current = millis();
client.print("
Timediff: ");
client.print(current - time);
client.print("ms.");
Serial.print("Timediff: ");
Serial.println(current - time);
time = millis();
}
// Close connection and free resources.
client.stop();
}
// Poll every 2ms (500Hz)
delay(5);
}