Particle Photon Temperature Logger

Moderator: leecollings

Post Reply
daandamhuis
Posts: 19
Joined: Tuesday 19 January 2016 10:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4608
Location: 's-Hertogenbosch
Contact:

Particle Photon Temperature Logger

Post by daandamhuis »

Hi All,

I don't know if this is the right place, but i managed to create a Particle Photon temperature logger with a DHT22 sensor. If someone has any suggestions to the code, please give them! :D

Code: Select all

#include "application.h"
#include "PietteTech_DHT/PietteTech_DHT.h"

// system defines
#define DHTTYPE                 DHT22 // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN                  3     // Digital pin for communications
#define DHT_SAMPLE_INTERVAL     10000  // Sample every minute
#define LUXPIN                  A1    // LDR Pin
#define READ_INTERVAL           10000

//Setup DHT Sensor reading 
void dht_wrapper(); 
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

//Setup Global Variables
unsigned int DHTnextSampleTime; // Next time we want to start sample
bool bDHTstarted;		        // flag to indicate we started acquisition
int n;                          // counter
int lux;

char VERSION[64] = "1.0";
char resultstr[64]; //String to store the sensor data

TCPClient client;
IPAddress remoteIP(192,168,178,196);

void setup() {
    DHTnextSampleTime = 0;  // Start the first sample immediately
    
}

void dht_wrapper() {
    DHT.isrCallback();
}

void loop() {
    if (millis() > DHTnextSampleTime) {
      
        if (!bDHTstarted) {		// start the sample
            DHT.acquire();
            bDHTstarted = true;
        }
        
        if (!DHT.acquiring()) {		// has sample completed?
            char tempInChar[32];
            char humidInChar[32];
    
            //Calculate Temperature
            float temp = (float)DHT.getCelsius();
            int temp1 = (temp - (int)temp) * 100;
            
            //Calculate Humidity
            float humid = (float)DHT.getHumidity();
            int humid1 = (humid - (int)humid) * 100;
            
            //Calculate Light
            float light_measurement = analogRead(LUXPIN);
            lux = (int)(light_measurement/4096*100);
    
            //Put Variables in Char
            sprintf(tempInChar,"%0d.%d", (int)temp, temp1);
            sprintf(humidInChar,"%0d.%d", (int)humid, humid1);
            
            if (client.connect(remoteIP, 8080)) {
                Particle.publish("Connection Domoticz", "Success", 60, PRIVATE);
                client.println("GET /json.htm?type=command&param=udevice&idx=1&nvalue=0&svalue=" + String(temp) + ";" + String(humid) + ";1 HTTP/1.1");
                client.println("Host: "+ remoteIP);
                client.println("Authorization: Basic <Authentication..>");
                client.println("Connection: close");
                client.println();
            }
            
            n++;  // increment counter
            bDHTstarted = false;  // reset the sample flag so we can take another
            DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL;  // set the time for next sample
        }
        
    }
}
RPi Model 2: Domoticz Server (Beta)
RPi Model B+: Smart Meter Slave (Stable)
Particle Photon (2x): Prototyping, Controlling LEDS and gathering Sensor data for Domoticz
Arduino Uno R3: with CC2500 Shield for Philips LivingColor Lights 1st Gen.
User avatar
StanHD
Posts: 347
Joined: Friday 12 July 2013 16:09
Target OS: Windows
Domoticz version:
Location: East Sussex, UK
Contact:

Re: Particle Photon Temperature Logger

Post by StanHD »

Wow ......... a what? 8-)
Domoticz Main - Intel nuc, Windows, RFXTRX433E. Lan Relay Boards, Aeon Z-Stick Gen 5, Evohome HGI80, Milight WiFi, MySensors Ethernet Gateway, Harmony Hub
Python:- Broadlink RM2, Sonos
HA-Bridge - Amazon Echo / Alexa
daandamhuis
Posts: 19
Joined: Tuesday 19 January 2016 10:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4608
Location: 's-Hertogenbosch
Contact:

Re: Particle Photon Temperature Logger

Post by daandamhuis »

A Particle Photon is a small development board with integrated wifi. It's pretty easy to setup and I find it useful for sensor data.
RPi Model 2: Domoticz Server (Beta)
RPi Model B+: Smart Meter Slave (Stable)
Particle Photon (2x): Prototyping, Controlling LEDS and gathering Sensor data for Domoticz
Arduino Uno R3: with CC2500 Shield for Philips LivingColor Lights 1st Gen.
alexsh1
Posts: 169
Joined: Wednesday 30 September 2015 11:50
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8975
Location: United Kingdom
Contact:

Re: Particle Photon Temperature Logger

Post by alexsh1 »

I am using it too with several sensors. However, several issues:

1) It may occasionally go out of sync with wifi
2) it is expensive (£21 is the cheapest here in the UK) though has got Wifi integrated but compare with other wifi boards (£5-8) is just too overpriced.
3) the firmware has to be updated regularly - not a problem but just an extra.
4) Not extremely low power friendly - wifi consumes a lot of power. For me this is not an issue as I am powering it from my iPhone charger.
5) I do not like DHT22 - I think using a low powered Si7021 via i2c is way much better and more precise.

Right now, I am looking at Electron (3G) to connect it to RPi and Domoticz - this may be an interesting way to have 3G backup connection or restart internet router / Domoticz if the main interenet connection fails though again expensive (priced $49 in the US).
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest