• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register

[Fully Supported] LM75 and LM76 temperature sensor
Hi everyone,

I was trying to set up the LM75 temperature sensor (using I2C). I worked on a new protocol based on the description - it compiles without errors, but I wasn't able to fully integrate it.

The C-code I wrote to access the sensor with the raspberry is pretty short and easy:

#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>
int main() {
    int fd = 0;
    fd = wiringPiI2CSetup(0x49);
    int rawtemperature = wiringPiI2CReadReg16(fd, 0x00);
    float temperature = (rawtemperature & 0x00ff) + ((rawtemperature >> 15)?0:0.5);
    printf("%.1lf\n", temperature);

I guess there are more changes necessary than just adding these few lines in the code a new dummy-protocol? Do I need to create a new Hardware Module?

My protocol lm75.c looks like this so far:
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdint.h>

#include "../../pilight.h"
#include "common.h"
#include "log.h"
#include "threads.h"
#include "protocol.h"
#include "hardware.h"
#include "binary.h"
#include "gc.h"
#include "json.h"
#include "lm75.h"
#include "../pilight/wiringPi.h"
#include <wiringPiI2C.h>

void *lm75Parse(void *param) {

    struct JsonNode *json = (struct JsonNode *)param;
    struct JsonNode *jsettings = NULL;
    int interval = 5;

    if((jsettings = json_find_member(json, "settings"))) {
        json_find_number(jsettings, "interval", &interval);

        int fd = 0;
        fd = wiringPiI2CSetup(0x49);

            if(fd>0) {

                int rawtemperature = wiringPiI2CReadReg16(fd, 0x00);
                float newtemperature = (rawtemperature & 0x00ff) + ((rawtemperature >> 15)?0:0.5);

                lm75->message = json_mkobject();
                JsonNode *code = json_mkobject();
                json_append_member(code, "id", json_mkstring(lm75->id));
                json_append_member(code, "temperature", json_mknumber(newtemperature));

                json_append_member(lm75->message, "code", code);
                json_append_member(lm75->message, "origin", json_mkstring("receiver"));
                json_append_member(lm75->message, "protocol", json_mkstring(lm75->id));
                pilight.broadcast(lm75->id, lm75->message);
                lm75->message = NULL;
            } else {
                logprintf(LOG_DEBUG, "error connecting to lm75 (probably i2c bus error from wiringPiI2CSetup - maybe wrong id? use i2cdetect to find out)");

    return (void *)NULL;

void lm75InitDev(JsonNode *jdevice) {
    char *output = json_stringify(jdevice, NULL);
    JsonNode *json = json_decode(output);
    threads_register("lm75", &lm75Parse, (void *)json);
    sfree((void *)&output);

void lm75Init(void) {
    protocol_set_id(lm75, "lm75");
    protocol_device_add(lm75, "lm75", "Lm75 temperature sensor");
    lm75->devtype = WEATHER;
    lm75->hwtype = SENSOR;

    options_add(&lm75->options, 't', "temperature", has_value, config_value, "^[0-9]{1,3}$");
    options_add(&lm75->options, 'i', "id", has_value, config_id, ".+");

    protocol_setting_add_number(lm75, "decimals", 1);
    protocol_setting_add_number(lm75, "temperature", 1);
    protocol_setting_add_number(lm75, "interval", 5);



What doesn't work?
The problem is, that the data sent out by the sensor does not show up on the webinterface even though pilight-receive receives data every 5 seconds:

        "temperature": 225,
        "origin": "receiver",
        "protocol": "lm75"

        "living": {
                "name": "Living",
                "temperature": {
                     "name": "lm75",
                     "protocol": [ "lm75" ],
                     "id": [{
                        "id": "0x49"
                     "temperature": 210

The webserver keeps showing the 210 from the configuration file, not the 225 coming from the sensor.

Thanks in advance!
A few checks:
If you stop the daemon, is the configuration temperature value different from before?
If you start pilight in debug mode: pilight-daemon -D, do you see these message:
[Jan 12 22:08:23:554270] pilight-daemon: DEBUG: broadcasted: {"origin":"config","type":3,"uuid":"0338-00-00-38-000300","devices":{"woonkamer":[ "klimaat" ]},"values":{"humidity":"473","temperature":"200"}}
I found there are to many errors to explain. I will upload a fixed version myself based on your code. Please test if that one works.

Thats fine if you upload a fixed version.Smile, because i have 4x LM75 in use AND some other I2C stuff (PCF8574).
Maybe integrate I2C in pilight ?
So is pilight more and more multy usable.Wink
How would we need to integrate I2C in another way as currently done by this protocol.

Already uploaded a new version yesterday.
ok, i will test and maybe use.
Like to install the lm75 protocoll.
but after new install with:

git clone --depth 5 -b development https://github.com/pilight/pilight.git

after setup.sh error:

[ 86%] Building C object CMakeFiles/pilight.dir/libs/websockets/output.c.o
[ 87%] Building C object CMakeFiles/pilight.dir/libs/websockets/server.c.o
[ 87%] Built target pilight
Scanning dependencies of target pilight_shared
Linking C shared library libpilight.so
[ 87%] Built target pilight_shared
Scanning dependencies of target pilight-control
[ 89%] Building C object CMakeFiles/pilight-control.dir/control.c.o
Linking C executable pilight-control
libpilight.so: undefined reference to `i2c_smbus_write_byte'
libpilight.so: undefined reference to `i2c_smbus_read_byte'
libpilight.so: undefined reference to `i2c_smbus_write_byte_data'
libpilight.so: undefined reference to `i2c_smbus_write_word_data'
libpilight.so: undefined reference to `i2c_smbus_read_word_data'
libpilight.so: undefined reference to `i2c_smbus_read_byte_data'
collect2: ld returned 1 exit status
make[2]: *** [pilight-control] Error 1
make[1]: *** [CMakeFiles/pilight-control.dir/all] Error 2
make: *** [all] Error 2

What's wrong ?
If you did ./setup.sh clean and then ./setup.sh you should receive a clear message of what's wrong.

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Partially Supported] TFA / Conrad Weather Yves 203 49,022 03-27-2020, 01:21 PM
Last Post: Ascenion
  [Fully Supported] KlikAanKlikUit Motion Sensor koen01 37 21,020 03-26-2020, 02:46 PM
Last Post: Gisto
  Digoo / Baldr / Nexus / Rubicson temperature/humidity sensor thielj 12 5,942 02-10-2020, 10:54 PM
Last Post: ha_username
  Support for Temperaturee sensor clona 4 1,382 02-10-2020, 02:52 PM
Last Post: clona
  gs-iwds07 window sensor Loggisch 48 24,627 12-09-2019, 07:14 PM
Last Post: curlymo
Lightbulb [Fully Supported] Kaku Door sensor (AMST-606) geerttttt 53 35,651 10-19-2019, 06:26 PM
Last Post: curlymo
  433MHz PIR sensor from Amazon ha_username 0 1,330 09-29-2019, 11:44 PM
Last Post: ha_username
  [Fully Supported] DHT22 IcedEarth 86 47,431 11-18-2018, 09:33 AM
Last Post: curlymo
  Pearl weatherstation sensor for FWS-686 & FWS-665 chklump 13 10,959 08-12-2018, 05:34 PM
Last Post: fourty2
  TFA 30.3160 Pool Sensor wseifert 4 2,389 05-30-2018, 09:24 AM
Last Post: wseifert

Forum Jump:

Browsing: 1 Guest(s)