Trimiterea a doua valori

Despre Internet Of Things

Re: Trimiterea a doua valori

Mesajde dberger » 31 Iul 2017, 22:38

informer scrie:de fapt de ce te deranjeaza? :lol:


Nimic, doar ca e o ciudatenie de program... care nu merge cum trebuie...
dberger
 
Mesaje: 81
Membru din: 23 Aug 2013, 17:07

Re: Trimiterea a doua valori

Mesajde dberger » 04 Aug 2017, 19:44

Cod: Selectaţi tot
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>


#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

Adafruit_BMP085 bmp;

//int t, h;

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192, 168, 0, 177);

// fill in your Domain Name Server address here:
IPAddress myDns(192, 168, 0, 1);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

// initialize the library instance:
EthernetClient client;

char server[] = "iot.robofun.ro";
//IPAddress server();

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 15L * 60000L; // delay between updates, in minutes
// the "L" is needed to use long type numbers

void setup() {
  // start serial port:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  while (1) {}
  }
 
  dht.begin();
  //give the ethernet module time to boot up:
  delay(2000);

  // start the Ethernet connection using a fixed IP address and DNS server:
  Ethernet.begin(mac, ip, myDns, gateway, subnet);
  // print the Ethernet board/shield's IP address:
  Serial.print("IP address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
       
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
 
  if (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    IoTpublish();
  }
}

// this method makes a HTTP connection to the server:
void IoTpublish() {
 
  //citeste umiditatea relativa DHT22
  int h = dht.readHumidity();
  //citeste temperatura DHT22
  int t = dht.readTemperature();
  //citeste temperatura BMP120
  float T = bmp.readTemperature();
  //citeste presiunea BMP120
  float P = bmp.readPressure();
  //calculeaza presiunea in mmHg
  int mmHg = P / 133.32239;
  //citeste altitudinea BMP120
  int alt = bmp.readAltitude();
 
  // close any connection before send a new request.
  // This will free the socket on the shield
  client.stop();
  String SENSOR_TOKEN1="7apqevfeekvlvr6q966k32roen";//temperatura
  String SENSOR_TOKEN2="pbdcsprl6ojo03smrve1gsi4mp";//umiditate
  String SENSOR_TOKEN3="avikdk04vllm5atsdkv90335mh";//indice Temp-umezeala-confort termic
  String SENSOR_TOKEN4="f0lssssljfl4hsiojgbj717vvn";//Presiunea

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("Conectat!");
   
    // send the HTTP GET request:
    client.println("GET /api/v1/senzor/" +SENSOR_TOKEN1+ "/input?value=" +t+ " HTTP/1.1");
    Serial.println("GET /api/v1/senzor/" +SENSOR_TOKEN1+ "/input?value=" +t+ " HTTP/1.1");
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();

    //lastConnectionTime = millis();
    // note the time that the connection was made:
    } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }

client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("Conectat!");

    // send the HTTP GET request:
    client.println("GET /api/v1/senzor/" +SENSOR_TOKEN2+ "/input?value=" +h+ " HTTP/1.1");
    Serial.println("GET /api/v1/senzor/" +SENSOR_TOKEN2+ "/input?value=" +h+ " HTTP/1.1");
    //Serial.println(data);
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();

    //lastConnectionTime = millis();

    // note the time that the connection was made:
    } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }

  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("Conectat!");

    // calculeaza indicele de confort termic
    int itu = t*0.81+h*0.01*(t*0.99-14.3)+46.3;//indice confort termic temperatura/umezeala

    // send the HTTP GET request:
    client.println("GET /api/v1/senzor/" +SENSOR_TOKEN3+ "/input?value=" +itu+ " HTTP/1.1");
    Serial.println("GET /api/v1/senzor/" +SENSOR_TOKEN3+ "/input?value=" +itu+ " HTTP/1.1");
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();

    //lastConnectionTime = millis();

    // note the time that the connection was made:
    } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("Conectat!");
   
    // send the HTTP GET request:
    client.println("GET /api/v1/senzor/" +SENSOR_TOKEN4+ "/input?value=" +mmHg+ " HTTP/1.1");
    Serial.println("GET /api/v1/senzor/" +SENSOR_TOKEN4+ "/input?value=" +mmHg+ " HTTP/1.1");
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();

    lastConnectionTime = millis();

    // note the time that the connection was made:
    } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}


Am adaugat inca un senzor BMP085 pentru presiune. Masoara si temperatura, dar pentru aceasta folosesc citirea de la DHT22. Pe baza temperaturii si a umiditatii relative de la DHT22 calculez indicele de confort termic.

Intrebarea este, cum trebuie sa arate codul, astfal incat, sa trimita valoarea doar daca aceasta se schimba, chiar daca s-a atins termenul de trimitere (in acest moment este de 15 minute)?
dberger
 
Mesaje: 81
Membru din: 23 Aug 2013, 17:07

Re: Trimiterea a doua valori

Mesajde dberger » 05 Aug 2017, 17:52

S-a rezolvat, trebuia doar sa "sap" cu google... Multumesc.
dberger
 
Mesaje: 81
Membru din: 23 Aug 2013, 17:07

Anterior

Înapoi la Internet Of Things