Calling more than one sensor within Arduin IDE sketch

6 years 4 months ago - 6 years 4 months ago #1785 by piman
Hello is there anyone who can help, on how I refer to more than one sensor within IDE sketch i.e. temperature sensor and door sensor.
Thanks in advance Andy.

Please Log in or Create an account to join the conversation.

6 years 4 months ago #1792 by EasyIoT

piman wrote: Hello is there anyone who can help, on how I refer to more than one sensor within IDE sketch i.e. temperature sensor and door sensor.
Thanks in advance Andy.


In temperature sketch also check one of DI pins. If pin is changed also send door/windows status.

Please Log in or Create an account to join the conversation.

6 years 3 months ago #1815 by piman
Thanks @EasyIoT, I have been trying to use a HTU21D which is I2c which is normally read as an analog, is it a problem mixing analogue and digital senses within easyiot on one node. I have been messing around with the script and not managed to get the data up to the server, this is where I've got to so far not sure whether I'm on the right track,
/*
 Created by EasyioT
  Created by piman

#include <ESP8266WiFi.h>
#include <Base64.h>

#include <Wire.h>
#include "HTU21D.h"

//Create an instance of the object
HTU21D myHumidity;

//AP definitions
#define AP_SSID "12345678"
#define AP_PASSWORD "87654321"

// EasyIoT server definitions
#define EIOT_USERNAME    "admin"
#define EIOT_PASSWORD    "test"
#define EIOT_IP_ADDRESS  "192.168.1.999"
#define EIOT_PORT        80
#define EIOT_NODE        "N1S0"

#define INPUT_PIN         2

//#define INPUT_PIN         5

#define USER_PWD_LEN      40


char unameenc[USER_PWD_LEN];
bool oldInputState;


void setup() {
  Serial.begin(9600);
  pinMode(INPUT_PIN, INPUT);
    myHumidity.begin();
pinMode(4, INPUT);
 pinMode(5, INPUT);
  wifiConnect();
    
  char uname[USER_PWD_LEN];
  String str = String(EIOT_USERNAME)+":"+String(EIOT_PASSWORD);  
  str.toCharArray(uname, USER_PWD_LEN); 
  memset(unameenc,0,sizeof(unameenc));
  base64_encode(unameenc, uname, strlen(uname));
  
 // oldInputState = !digitalRead(INPUT_PIN);
}

void loop() {
   float humd = myHumidity.readHumidity();
  float temp = myHumidity.readTemperature();

  delay(1000);
  int inputState = digitalRead(temp);



  if (inputState != oldInputState);
  {
    sendInputState(inputState);
    oldInputState = inputState;
    
  }
}

void wifiConnect()
{
    Serial.print("Connecting to AP");
    WiFi.begin(AP_SSID, AP_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected");  
}

void sendInputState(bool inputState)

{  
   WiFiClient client;
   
   while(!client.connect(EIOT_IP_ADDRESS, EIOT_PORT)) {
    Serial.println("connection failed");
    wifiConnect(); 
  }
 
  String url = "";
  String command = "";
  
  
  if (inputState)
    command = " ControlOn";
  else
    command = "ControlOff";  //"temp""humd";
   
  
  url = "/Api/EasyIoT/Control/Module/Virtual/"+ String(EIOT_NODE) + "/"+command; // generate EasIoT server node URL

  Serial.print("POST data to URL: ");
  Serial.println(url);
  
  client.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + String(EIOT_IP_ADDRESS) + "\r\n" +
               
               "Connection: close\r\n" + 
               "Authorization: Basic " + unameenc + " \r\n" + 
               "Content-Length: 0\r\n" + 
               "\r\n");

  delay(100);
    while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  
  Serial.println();
  Serial.println("Connection closed");
    delay(2000);

}
Thanks you Andy

Please Log in or Create an account to join the conversation.

6 years 3 months ago #1863 by piman
Hi can anyone help this is as far as I've got so far with my I2c temperature and humidity sensor I can get the data to EasyIoT server but it doesn't seem to log the data, also I cannot get them to display the data individually.
/*
  Created by Igor Jarc
 See http://iot-playground.com for details
 Please use community forum on website do not contact author directly
 
 External libraries:
 - https://github.com/adamvr/arduino-base64
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */
#include <ESP8266WiFi.h>
#include <Base64.h>

#include <Wire.h>
#include "HTU21D.h"


//AP definitions
#define AP_SSID "xxx"
#define AP_PASSWORD "xxx"

// EasyIoT server definitions
#define EIOT_USERNAME    "admin"
#define EIOT_PASSWORD    "test"
#define EIOT_IP_ADDRESS  "192.168.1.xxx"
#define EIOT_PORT        80
#define EIOT_NODE        "N1S0"

#define INPUT_PIN         2
#define OUTPUT_PIN         4
//#define INPUT_PIN         5

#define USER_PWD_LEN      40



char unameenc[USER_PWD_LEN];
bool oldInputState;
bool getEvent(HTU21D myHumidity);

//Create an instance of the object
HTU21D myHumidity;

void setup() {
  Serial.begin(9600);
 // pinMode(2, INPUT);
 // pinMode(4, OUTPUT);	
 // pinMode(5, INPUT);
    myHumidity.begin();
//Wire.begin(4, 5);
  wifiConnect();
  
  
  char uname[USER_PWD_LEN];
  String str = String(EIOT_USERNAME)+":"+String(EIOT_PASSWORD);  
  str.toCharArray(uname, USER_PWD_LEN); 
  memset(unameenc,0,sizeof(unameenc));
  base64_encode(unameenc, uname, strlen(uname));
  
oldInputState = !digitalRead(INPUT_PIN);

}

void loop() {
   float humd = myHumidity.readHumidity();
   float temp = myHumidity.readTemperature();

  delay(1000);
  int inputState = (temp);
 

  if (inputState != oldInputState);
  {
    sendInputState(inputState);
    oldInputState = inputState;
    
  }
}

void wifiConnect()
{
    Serial.print("Connecting to AP");
    WiFi.begin(AP_SSID, AP_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
    delay(2000);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected"); 
}

void sendInputState(bool inputState)
{  
   WiFiClient client;
 

   while(!client.connect(EIOT_IP_ADDRESS, EIOT_PORT)) {
    Serial.println("connection failed");
    wifiConnect(); 
  }
 
  String url = "";
  //String url = "";
  //String command = "";
  
 
  
 // if (inputState)
   // command = " ControlOn";
    
 // else
    //command = "ControlOff";  
    delay(1000);
  {
  
  // Read temperature as Celsius
  //int t = myHumidity.readTemperature();
  //delay(1000);
  // Wire.beginTransmission (0x40);
  //  Wire.read ();
  url = "/Api/EasyIoT/Control/Module/Virtual/"+String(EIOT_NODE) +"/ControlLevel/""Temp>"+String(myHumidity.readTemperature())+"-"
 "Humid>"+String(myHumidity.readHumidity()); 
   Serial.print("POST data to URL: ");
  Serial.println(url);

  client.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + String(EIOT_IP_ADDRESS) + "\r\n" +
               
               "Connection: close\r\n" + 
               "Authorization: Basic " + unameenc + " \r\n" + 
               "Content-Length: 0\r\n" + 
               "\r\n");

  
  
  
  
   
  delay(1000);
  // Reading temperature and humidity
 // int h = myHumidity.readHumidity();
  //delay(1000);
//  url  +String(myHumidity.readHumidity());
 // Serial.print("POST data to URL: ");
  //Serial.println(url);
  
  client.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + String(EIOT_IP_ADDRESS) + "\r\n" +
               
               "Connection: close\r\n" + 
               "Authorization: Basic " + unameenc + " \r\n" + 
               "Content-Length: 0\r\n" + 
               "\r\n");
               
{
  delay(2000);

}
    while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
    
  }
  
  Serial.println();
  Serial.println("Connection closed");
    delay(4000);

}


}

Thanks for your help in advance

Please Log in or Create an account to join the conversation.

6 years 3 months ago #1865 by EasyIoT

piman wrote: Hi can anyone help this is as far as I've got so far with my I2c temperature and humidity sensor I can get the data to EasyIoT server but it doesn't seem to log the data, also I cannot get them to display the data individually.

/*
  Created by Igor Jarc
 See http://iot-playground.com for details
 Please use community forum on website do not contact author directly
 
 External libraries:
 - https://github.com/adamvr/arduino-base64
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */
#include <ESP8266WiFi.h>
#include <Base64.h>

#include <Wire.h>
#include "HTU21D.h"


//AP definitions
#define AP_SSID "xxx"
#define AP_PASSWORD "xxx"

// EasyIoT server definitions
#define EIOT_USERNAME    "admin"
#define EIOT_PASSWORD    "test"
#define EIOT_IP_ADDRESS  "192.168.1.xxx"
#define EIOT_PORT        80
#define EIOT_NODE        "N1S0"

#define INPUT_PIN         2
#define OUTPUT_PIN         4
//#define INPUT_PIN         5

#define USER_PWD_LEN      40



char unameenc[USER_PWD_LEN];
bool oldInputState;
bool getEvent(HTU21D myHumidity);

//Create an instance of the object
HTU21D myHumidity;

void setup() {
  Serial.begin(9600);
 // pinMode(2, INPUT);
 // pinMode(4, OUTPUT);	
 // pinMode(5, INPUT);
    myHumidity.begin();
//Wire.begin(4, 5);
  wifiConnect();
  
  
  char uname[USER_PWD_LEN];
  String str = String(EIOT_USERNAME)+":"+String(EIOT_PASSWORD);  
  str.toCharArray(uname, USER_PWD_LEN); 
  memset(unameenc,0,sizeof(unameenc));
  base64_encode(unameenc, uname, strlen(uname));
  
oldInputState = !digitalRead(INPUT_PIN);

}

void loop() {
   float humd = myHumidity.readHumidity();
   float temp = myHumidity.readTemperature();

  delay(1000);
  int inputState = (temp);
 

  if (inputState != oldInputState);
  {
    sendInputState(inputState);
    oldInputState = inputState;
    
  }
}

void wifiConnect()
{
    Serial.print("Connecting to AP");
    WiFi.begin(AP_SSID, AP_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
    delay(2000);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected"); 
}

void sendInputState(bool inputState)
{  
   WiFiClient client;
 

   while(!client.connect(EIOT_IP_ADDRESS, EIOT_PORT)) {
    Serial.println("connection failed");
    wifiConnect(); 
  }
 
  String url = "";
  //String url = "";
  //String command = "";
  
 
  
 // if (inputState)
   // command = " ControlOn";
    
 // else
    //command = "ControlOff";  
    delay(1000);
  {
  
  // Read temperature as Celsius
  //int t = myHumidity.readTemperature();
  //delay(1000);
  // Wire.beginTransmission (0x40);
  //  Wire.read ();
  url = "/Api/EasyIoT/Control/Module/Virtual/"+String(EIOT_NODE) +"/ControlLevel/""Temp>"+String(myHumidity.readTemperature())+"-"
 "Humid>"+String(myHumidity.readHumidity()); 
   Serial.print("POST data to URL: ");
  Serial.println(url);

  client.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + String(EIOT_IP_ADDRESS) + "\r\n" +
               
               "Connection: close\r\n" + 
               "Authorization: Basic " + unameenc + " \r\n" + 
               "Content-Length: 0\r\n" + 
               "\r\n");

  
  
  
  
   
  delay(1000);
  // Reading temperature and humidity
 // int h = myHumidity.readHumidity();
  //delay(1000);
//  url  +String(myHumidity.readHumidity());
 // Serial.print("POST data to URL: ");
  //Serial.println(url);
  
  client.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + String(EIOT_IP_ADDRESS) + "\r\n" +
               
               "Connection: close\r\n" + 
               "Authorization: Basic " + unameenc + " \r\n" + 
               "Content-Length: 0\r\n" + 
               "\r\n");
               
{
  delay(2000);

}
    while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
    
  }
  
  Serial.println();
  Serial.println("Connection closed");
    delay(4000);

}


}

Thanks for your help in advance


Just asking. Did you enable data logging in WEB UI configuration for parameter? If data is changed in UI and data logging is enabled then you should see history chart.

Please Log in or Create an account to join the conversation.

6 years 3 months ago #1869 by piman
Thank's, Yes I checked the data logging parameters and yes it is enable.

Please Log in or Create an account to join the conversation.

Time to create page: 0.227 seconds

Forum latest

  • No posts to display.