Fasensor: Difference between revisions

From Futuragora Wiki
No edit summary
No edit summary
Line 174: Line 174:


https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/Adafruit_Sensor
==PHP Code Arduino Mysql==
Create Table:
<pre>
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 ;
</pre>
==PHP Code==
php code (fasensor) add.php:
<pre>
<?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"]."')");
?>
</pre>
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.
#include <Adafruit_BMP085.h>
#include <dht11.h>
#include <SPI.h>
#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;
#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>
#include <dht11.h>
#include <Adafruit_BMP085.h>
#include <SPI.h>
#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;
#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;
    }
  }
}


[[Category:Projectos_Futuragora]]
[[Category:Projectos_Futuragora]]
[[Category:Opensenses]]
[[Category:Opensenses]]

Revision as of 18:46, 21 July 2018

Fasensor é um sensor montado a partir de um arduino, com sensor de temperatura, humidade e pressão atmosférica. Pode consultar o projecto em: Dados recolhidos: Temperatura, Humidade, Pressão Atmosférica

Opensenses Page

Fasensor

Componentes

Arduino ethernet

BMP085

DHT11


Be the change!

Code Test sensors

#include <Wire.h>
#include <Adafruit_BMP085.h>

/*************************************************** 
  This is an example for the BMP085 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit BMP085 Breakout 
  ----> https://www.adafruit.com/products/391

  These displays use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/
#include "DHT.h"

#define DHTPIN A1     // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT11   // DHT 22  (AM2302), AM2321

// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used here
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;




double Fahrenheit(double celsius)
{
  return 1.8 * celsius + 32;
}

// fast integer version with rounding
//int Celcius2Fahrenheit(int celcius)
//{
//  return (celsius * 18 + 5)/10 + 32;
//}


//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
  return celsius + 273.15;
}

// dewPoint function NOAA
// reference (1) : http://wahiduddin.net/calc/density_algorithms.htm
// reference (2) : http://www.colorado.edu/geography/weather_station/Geog_site/about.htm
//
double dewPoint(double celsius, double humidity)
{
  // (1) Saturation Vapor Pressure = ESGG(T)
  double RATIO = 373.15 / (273.15 + celsius);
  double RHS = -7.90298 * (RATIO - 1);
  RHS += 5.02808 * log10(RATIO);
  RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
  RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
  RHS += log10(1013.246);

        // factor -3 is to adjust units - Vapor Pressure SVP * humidity
  double VP = pow(10, RHS - 3) * humidity;

        // (2) DEWPOINT = F(Vapor Pressure)
  double T = log(VP/0.61078);   // temp var
  return (241.88 * T) / (17.558 - T);
}

// delta max = 0.6544 wrt dewPoint()
// 6.9 x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
  double Td = (b * temp) / (a - temp);
  return Td;
}



  
void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  while (1) {}
  }
}
void loop() {
    Serial.print("Humidity = ");
    Serial.print(dht.readHumidity());
    Serial.println(" *H");
    
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");

  // you can get a more precise measurement of altitude
  // if you know the current sea level pressure which will
  // vary with weather and such. If it is 1015 millibars
  // that is equal to 101500 Pascals.
    Serial.print("Real altitude = ");
    Serial.print(bmp.readAltitude(101500));
    Serial.println(" meters");
    
    Serial.println();
    delay(5000);
}

PHP and Mysql

Create a database with three tables: temperature, humidity, pressure. Use the following code:


Add 2 files to your server: connect.php and add.php:





Code

Libraries

https://github.com/adafruit/Adafruit_Sensor


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;
   }
 }

}