Opensenses: Difference between revisions

From Futuragora Wiki
No edit summary
No edit summary
Line 486: Line 486:
[[FASensor2]] Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos.
[[FASensor2]] Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos.
[[FASensor3]] Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos.
[[FASensor3]] Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos.
[[FASensor4]] Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos.
[[FASensor5]] Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos.


[[Category:Projectos Futuragora]]
[[Category:Projectos Futuragora]]
[[Category:Opensenses]]
[[Category:Opensenses]]

Revision as of 03:07, 17 July 2018

Codename: opensenses

http://lab.futuragora.pt/opensenses/

O Opensenses é um sistema de sensores que monitorizam variados dados climatéricos (temperatura, pressão atmosférica, humidade ou radiação), dados energéticos (produção solar, tarifário bi-horario ou carga de pilha ou bateria) e  está relacionado com os restantes projectos de automação e arduino. O objectivo era estabelecer uma central de informação que colhe os dados de vários arduinos remotos, e que foi conseguido através de ferramentas opensource e com muita prototipagem. O Open Senses representa a conjugação dos projectos de automação relacionados com a central meteo DIY, recolha de dados sensorais e a sua compilação num servidor de bases de dados. Esses dados constituiem os olhos e sentidos da investigação.

Traduzido do inglês este projecto representa sentidos livres ou abertos. Assenta num modelo código livre e de rapida prototipagem com a apresentação de um produto final que qualquer pessoa possa ligar à sua rede local e começar a coletar informações sensorais. Como base temos sensores de temperatura, humidade, pressão, luminosidade entre outros. Mais avançados poderam ser ligados sensores como tubo Geiser, sensor de gaz butano, de fumo, de ph, de corrente electrica, de entre milhares. Esse milhares de compomentes permitiram criar uma base de dados em tempo real daquilo que se está a passar no mundo, permitindo-nos gerir mais eficientemente os nossos recursos.

Este projecto está relacionado com os restantes projectos de automação e arduino. O objectivo é estabelecer uma central de informação que colhe os dados de vários senores remotos. Numa primeira fase pretendeu-se colher os dados dos sensores e inseri-los em bases de dados no servidor. A partir daí os dados foram manipulados e graficamente desmonstrados.

Protótipos em produção:

Fasensor2

Fasensor5

Fasensor1

Fasensor3

O FA_Sensor7 é um do projecto Open Senses.

PHP Code Arduino Mysql

Create Table:

CREATE TABLE `fasensor7`.`temperature` (
`id` INT( 255 ) NOT NULL AUTO_INCREMENT ,
`timestamp` VARCHAR( 255 ) NOT NULL ,
`temperature` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;

CREATE TABLE `fasensor7`.`pressure` (
`id` INT( 255 ) NOT NULL AUTO_INCREMENT ,
`timestamp` VARCHAR( 255 ) NOT NULL ,
`pressure` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;

CREATE TABLE `fasensor7`.`humidity` (
`id` INT( 255 ) NOT NULL AUTO_INCREMENT ,
`timestamp` VARCHAR( 255 ) NOT NULL ,
`temperature` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;

CREATE TABLE `fasensor7`.`light` (
`id` INT( 255 ) NOT NULL AUTO_INCREMENT ,
`timestamp` VARCHAR( 255 ) NOT NULL ,
`pressure` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;

PHP Code

php code (fasensor) add.php:

 
<?php 
    include("conec.php"); 
    $link=Conection(); 
    $timestamp=date('Y-m-d H:i:s'); 

mysql_query("insert into temperature (timestamp,temperature)  values  ('$timestamp', '".$_REQUEST["temperature"]."')"); 
mysql_query ("insert into pressure (timestamp,pressure)  values  ('$timestamp', '".$_REQUEST["pressure"]."')"); 
mysql_query ("insert into humidity (timestamp,humidity)  values  ('$timestamp', '".$_REQUEST["humidity"]."')"); 
mysql_query ("insert into temperature2 (timestamp,temperature2)  values  ('$timestamp', '".$_REQUEST["temperature2"]."')"); 
mysql_query ("insert into dew (timestamp,dew)  values ('$timestamp',  '".$_REQUEST["dew"]."')"); 
mysql_query ("insert into light (timestamp,light)  values ('$timestamp',  '".$_REQUEST["light"]."')"); 
?> 

Arduino code: https://code.google.com/p/arduino-hub/source/browse/trunk/sketches/FA_Sensor1_Zeta_O/FA_Sensor1_Zeta_O.ino

Mudei o FASENSOR! todas as tabelas o campo timestamp de varchar para datetime

http://opensenses.futuragora.pt OPENSENSES

OpenSenses: http://dev.futuragora.pt/~dev/opensenses


FA Sensor4 - MS05 Projecto: http://www.futuragora.pt/projetos/open-senses/fa_sensor4/ Página: http://dev.futuragora.pt/sensorcentral/fasensor4/ Graficos: https://thingspeak.com/channels/53957/ Public view: https://thingspeak.com/channels/53957/ Viewing Data: https://api.thingspeak.com/channels/53957/feed.json?key=T2UVSSH5O3AVYJ8T

Local: Olaias Sensores: Humidade, Pressão, Temperatura Latitude: Longitude: Descrição: O FA_Sensor4 é o segundo prototipo funcional do projecto OpenSenses. O Open Senses representa a conjugação dos projectos de automação relacionados com a central meteo DIY, recolha de dados sensorais e a sua compilação num servidor de bases de dados. Esses dados constituiem os olhos e sentidos da investigação. Projecto FA Sensor 1 na Futuragora

Chart ( Grafico): http://dev.futuragora.pt:89/sensorcentral/fasensor4/graph_temp.php Last 10: http://dev.futuragora.pt:89/sensorcentral/fasensor4/last10.php Agora: http://dev.futuragora.pt:89/sensorcentral/fasensor4/last_values.php


FA Sensor5

Projecto: http://www.futuragora.pt/projetos/open-senses/fa_sensor5/ Página: http://dev.futuragora.pt:89/sensorcentral/fasensor5/ Graficos / https://thingspeak.com/channels/51826 API http://api.thingspeak.com/channels/51826/feed.json?key=CIFMMGYWGU9HZ894 CIFMMGYWGU9HZ894 roltel@roltel.net samuelrolando

Local: Lisboa Sensores: Humidade, Pressão, Temperatura

Descrição: O FA_Sensor1 é o primeiro prototipo do projecto Open Senses. O Open Senses representa a conjugação dos projectos de automação relacionados com a central meteo DIY, recolha de dados sensorais e a sua compilação num servidor de bases de dados. Esses dados constituiem os olhos e sentidos da investigação. Projecto FA Sensor 1 na Futuragora

Chart (Gráfico): http://dev.futuragora.pt:89/sensorcentral/fasensor5/graph_temp.php Last 10: http://dev.futuragora.pt:89/sensorcentral/fasensor5/last10.php Agora: http://dev.futuragora.pt:89/sensorcentral/fasensor5/last_values.php


GITHUB - Arduino HUB Lib and Sketches: add user config to git: git config --global user.email "roltel@roltel.net" ssh-keygen -t rsa -b 4096 -C "roltel@roltel.net" eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa leafpad ~/.ssh/id_rsa.pub


Clone: git clone git@github.com:roltel/arduino-hub.git https://help.github.com/articles/generating-ssh-keys/#step-4-add-your-ssh-key-to-your-account


Mudei o FASENSOR! todas as tabelas o campo timestamp de varchar para datetime

// This sketch uses a DHT11 sensor to report temperature, humidity and dew point data to http://www.thingspeak.com. // https://github.com/roltel/arduino-hub/blob/master/sketches/DHT11_Sensor_Read/DHT11_Sensor_Read.ino // Sketch tested with an Arduino Uno, a HanRun Ethernet shield and a DHT11 temperature and humidity sensor. // // See http://playground.arduino.cc/main/DHT11Lib for the origins of the temperature, humidity and dew point functions.

  1. include <Adafruit_BMP085.h>
  2. include <dht11.h>
  3. include <SPI.h>
  4. include <Ethernet.h>

Adafruit_BMP085 bmp; // ThingSpeak Settings char thingSpeakAddress[] = "api.thingspeak.com"; String writeAPIKey = "CIFMMGYWGU9HZ894"; // Add your Thingspeak API key here - mudar a key EthernetClient client; // Temperature sensor settings dht11 DHT11;

  1. define DHT11PIN A2

const int ONE_MINUTE = 60 * 1000; int status; int failedConnectionAttempCounter; //Rounds down (via intermediary integer conversion truncation) //See : http://lordvon64.blogspot.co.uk/2012/01/simple-arduino-double-to-string.html String dblToString(double input, int decimalPlaces) { if( decimalPlaces != 0) { String string = String((int)(input*pow(10,decimalPlaces))); if(abs(input) < 1) { if(input > 0) { string = "0" + string; } else if(input < 0) { string = string.substring(0,1) + "0" + string.substring(1); } } return string.substring(0,string.length()-decimalPlaces) + "." + string.substring(string.length() - decimalPlaces); } else { return String((int)input); } } // dewPoint function NOAA // reference: http://wahiduddin.net/calc/density_algorithms.htm double dewPoint(double celsius, double humidity) { double A0= 373.15/(273.15 + celsius); double SUM = -7.90298 * (A0-1); SUM += 5.02808 * log10(A0); SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ; SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ; SUM += log10(1013.246); double VP = pow(10, SUM-3) * humidity; double T = log(VP/0.61078); // temp var return (241.88 * T) / (17.558-T); } void setup() { Serial.begin(57600); Serial.println("DHT11 Temperature Sensor Program"); Serial.print("DHT11 library version: "); Serial.println(DHT11LIB_VERSION); Serial.println(); connectToInternet(); } void connectToInternet() { if (client.connected()) { client.stop(); } Serial.println("Connecting to the internet via ethernet..."); // the media access control (ethernet hardware) address for the shield // Leave this as is if your MAC address is not labelled on your ethernet shield byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore for(;;){

} } Serial.println(Ethernet.localIP()); } void loop() { Serial.println("\n"); int dht11ReadingStatus = DHT11.read(DHT11PIN); Serial.print("Reading sensor..."); switch (dht11ReadingStatus) { case DHTLIB_OK: Serial.println("Success!"); break; case DHTLIB_ERROR_CHECKSUM: Serial.println("Checksum error"); break; case DHTLIB_ERROR_TIMEOUT: Serial.println("Timeout error"); break; default: Serial.println("Unknown error"); break; } double dewPointCelcius = dewPoint(DHT11.temperature, DHT11.humidity); ReportTemperatureToSerialOut(DHT11.temperature, DHT11.humidity, dewPointCelcius); ReportTemperatureToThingspeak(DHT11.temperature, DHT11.humidity, dewPointCelcius); } void ReportTemperatureToSerialOut(int temperature, int humidity, double dewPointCelcius) { Serial.print("Temperature (oC): "); Serial.println((float)temperature, 2); Serial.print("Humidity (%): "); Serial.println((float)humidity, 2); Serial.print("Dew Point (oC): "); Serial.println(dewPointCelcius); } void ReportTemperatureToThingspeak(int temperature, int humidity, double dewPoint) { // Use short field names i.e. 1 instead of field1 String fields = "1=" + String(temperature, DEC); fields += "&2=" + String(humidity, DEC); fields += "&3=" + dblToString(dewPoint, 2); Serial.println(fields); if (client.connect(thingSpeakAddress, 80)) { Serial.println("Connected to thingspeak.com"); // Create HTTP POST Data client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(fields.length()); client.print("\n\n"); client.print(fields); Serial.print(fields); Serial.print("\n"); Serial.println("Fields sent sent to www.thingspeak.com"); //delay(ONE_MINUTE); delay (59000); } else { Serial.println("Connection to thingSpeak Failed"); Serial.println(); failedConnectionAttempCounter++; // Re-start the ethernet connection after three failed connection attempts if (failedConnectionAttempCounter > 3 ) { Serial.println("Re-starting the ethernet connection..."); connectToInternet(); failedConnectionAttempCounter = 0; } } }




cript,applet, frame


Codigo:

   #include <Wire.h>
  1. include <dht11.h>
  2. include <Adafruit_BMP085.h>
  3. include <SPI.h>
  4. include <Ethernet.h>

Adafruit_BMP085 bmp; // ThingSpeak Settings char thingSpeakAddress[] = "api.thingspeak.com"; String writeAPIKey = "N8XZBP88WGR87TDD"; // Add your Thingspeak API key here EthernetClient client; // Temperature sensor settings dht11 DHT11;

  1. define DHT11PIN A2

const int ONE_MINUTE = 60 * 1000; int status; int failedConnectionAttempCounter;

//Rounds down (via intermediary integer conversion truncation) //See : http://lordvon64.blogspot.co.uk/2012/01/simple-arduino-double-to-string.html String dblToString(double input, int decimalPlaces) {

 if ( decimalPlaces != 0)
 {
   String string = String((int)(input * pow(10, decimalPlaces)));
   if (abs(input) < 1)
   {
     if (input > 0)
     {
       string = "0" + string;
     }
     else if (input < 0)
     {
       string = string.substring(0, 1) + "0" + string.substring(1);
     }
   }
   return string.substring(0, string.length() - decimalPlaces) + "." + string.substring(string.length() - decimalPlaces);
 }
 else
 {
   return String((int)input);
 }

}

// dewPoint function NOAA // reference: http://wahiduddin.net/calc/density_algorithms.htm double dewPoint(double celsius, double humidity) {

 double A0 = 373.15 / (273.15 + celsius);
 double SUM = -7.90298 * (A0 - 1);
 SUM += 5.02808 * log10(A0);
 SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1 / A0))) - 1) ;
 SUM += 8.1328e-3 * (pow(10, (-3.49149 * (A0 - 1))) - 1) ;
 SUM += log10(1013.246);
 double VP = pow(10, SUM - 3) * humidity;
 double T = log(VP / 0.61078); // temp var
 return (241.88 * T) / (17.558 - T);

}

void setup() {

 Serial.begin(9600);
 Serial.println("DHT11 Temperature Sensor Program");
 Serial.print("DHT11 library version: ");
 Serial.println(DHT11LIB_VERSION);
 Serial.println();
 if (!bmp.begin()) {
 Serial.println("Could not find a valid BMP085 sensor, check wiring!");
 while (1) {}
 }
 connectToInternet();

}

void connectToInternet() {

 if (client.connected())
 {
   client.stop();
 }
 Serial.println("Connecting to the internet via ethernet...");
 // the media access control (ethernet hardware) address for the shield
 // Leave this as is if your MAC address is not labelled on your ethernet shield
 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xAD, 0xED };
 if (Ethernet.begin(mac) == 0) {
   Serial.println("Failed to configure Ethernet using DHCP");
   // no point in carrying on, so do nothing forevermore
   for (;;) {
     ;
   }
 }
 Serial.println(Ethernet.localIP());

} void loop() {

 Serial.println("\n");
 int dht11ReadingStatus = DHT11.read(DHT11PIN);
 Serial.print("Reading sensor...");
 switch (dht11ReadingStatus)
 {
   case DHTLIB_OK:
     Serial.println("DHT Success!");
     break;
   case DHTLIB_ERROR_CHECKSUM:
     Serial.println("DHT Checksum error");
     break;
   case DHTLIB_ERROR_TIMEOUT:
     Serial.println("DHT Timeout error");
     break;
   default:
     Serial.println("DHT Unknown error");
     break;
 }
 double dewPointCelcius = dewPoint(DHT11.temperature, DHT11.humidity);
 ReportTemperatureToSerialOut(DHT11.temperature, DHT11.humidity, dewPointCelcius);
 ReportTemperatureToThingspeak(DHT11.temperature, DHT11.humidity, dewPointCelcius);

}

void ReportTemperatureToSerialOut(int temperature, int humidity, double dewPointCelcius) {

 Serial.print("Temperature (oC): ");
 Serial.println((float)temperature, 2);
 Serial.print("Humidity (%): ");
 Serial.println((float)humidity, 2);
 Serial.print("Dew Point (oC): ");
 Serial.println(dewPointCelcius);
 Serial.print("Pressure (bar???): ");
 Serial.println(bmp.readPressure());
 

}

void ReportTemperatureToThingspeak(int temperature, int humidity, double dewPoint) {

 // Use short field names i.e. 1 instead of field1
 String fields = "1=" + String(temperature, DEC);
 fields += "&2=" + String(humidity, DEC);
 fields += "&3=" + dblToString(dewPoint, 2);
 fields += "&4=" + String(bmp.readPressure(), DEC);
 Serial.println(fields);
 if (client.connect(thingSpeakAddress, 80))
 {
   Serial.println("Connected to thingspeak.com");
   // Create HTTP POST Data
   client.print("POST /update HTTP/1.1\n");
   client.print("Host: api.thingspeak.com\n");
   client.print("Connection: close\n");
   client.print("X-THINGSPEAKAPIKEY: " + writeAPIKey + "\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");
   client.print(fields.length());
   client.print("\n\n");
   client.print(fields);
   Serial.print(fields);
   Serial.print("\n");
   Serial.println("Fields sent sent to www.thingspeak.com");
   //delay(ONE_MINUTE);
   delay (59000);
 }
 else
 {
   Serial.println("Connection to thingSpeak Failed");
   Serial.println();
   failedConnectionAttempCounter++;
   // Re-start the ethernet connection after three failed connection attempts
   if (failedConnectionAttempCounter > 3 )
   {
     Serial.println("Re-starting the ethernet connection...");
     connectToInternet();
     failedConnectionAttempCounter = 0;
   }
 }

}

Sub-Projectos

FASensor1 Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos. FASensor2 Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos. FASensor3 Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos. FASensor5 Monitor de Temperatura, Humidade, Pressão e outros dados metereológicos.