Problems with GPIO push button on self build emonPi

(Paul) #59

Well yes there are some indentation errors there, for some reason you have duplicated some code one level in


import glob
import time
import paho.mqtt.publish as publish
import RPi.GPIO as gpio

Broker = ''
auth = {
    'username': 'emonpi',
    'password': 'emonpimqtt2016',

Sensors = {{'name':'SENSOR_A','id':'28-800000abc123','pin':1,'on':20,'off':15},

def read_temp(sensorid):
    valid = False
    temp = 0
    device_file = '/sys/bus/w1/devices/' + sensorid + '/w1_slave'
    with open(device_file, 'r') as f:
        for line in f:
            if line.strip()[-3:] == 'YES':
                valid = True
            temp_pos = line.find(' t=')
            if temp_pos != -1:
                temp = float(line[temp_pos + 3:]) / 1000.0
    if valid:
        return temp
        return None

def publish_data(topic, value):
    publish.single(topic, str(value),
                    hostname=Broker, port=1883,


for sensor in Sensors:
    gpio.setup(sensor['pin'], gpio.OUT)
    gpio.output(sensor['pin'], gpio.HIGH)
    sensor['status'] = 0

while True:
    for sensor in Sensors:
        temp = read_temp(sensor['id'])
        if temp is not None:
            publish_data('emon/Temperatures/' + sensor['name'] + '/values', temp)
            #publish_data('emon/' + sensor['name'] + 'Temperature/values', temp)
            if temp >= sensor['on']:
                gpio.output(sensor['pin'], gpio.LOW)
                sensor['status'] = 1
            elif temp <= sensor['off']:
                gpio.output(sensor['pin'], gpio.HIGH)
                sensor['status'] = 0

        publish_data('emon/Fans/' + sensor['name'] + '/values', sensor['status'])
        #publish_data('emon/' + sensor['name'] + '/Status/values', sensor['status'])


(tonertiffi) #60

Convinced you a genius :smiley:

(tonertiffi) #61

In my effort i managed to break this, it does not update the values, if i hit refresh it works , go out, go back in values updated,never turns red

(tonertiffi) #62

Check pc time bottom left:smiley:

(Paul) #63

Sorry I don’t follow, are you saying emoncms is no longer refreshing?

Try using ctrl-f5 to see if that fixes it OR has your log in session timed out?

(tonertiffi) #64


it works everywhere else except for the feeds page.

(Paul) #65

I’m still not sure what you mean, you are showing us the graph page which is data derived from the feeds, it cannot update unless the feeds update. Which is why I suggested a clear cache to the browser.

(Paul) #66

What is that “paused” button?


(tonertiffi) #67

Gmail is paused :slight_smile:

(Paul) #68

ahh ok! :slight_smile:

(tonertiffi) #69

Ok this is what i do, and the results.
I go to the inputs and select a feed add it (log to feed)
I go to the feed page its not updating.
I delete that feed i just created (log to feed), the rest start updating.
i go out of the feed page, i go back in no feeds updating

(tonertiffi) #70

I changed on the My account,My profile, Beta Features:

Device Module Beta

was On, to OFF
started working 100%

(tonertiffi) #71

Its now 24:30pm here, will run it till the morning and let you know, If its still updating ok.

(Paul) #72

Please do. If the issue persists it sounds like something @TrystanLea should be aware of.

Just as another test, can you try using input and feed names without any special characters, it should be able to handle a couple of underscores, but you never know.

(tonertiffi) #73

Hi @pb66 ran it through the night, till now no problem, feeds r there, everything working 100%.As long as i do not switch to

(tonertiffi) #74

Hi @pb66, wondered on something, some off the gpio pins,on the RPI seem to have a low voltage not activated. I noticed that when i plug in the relay, eg IN1 signal to a random gpio pin on the RPI, the led on the pba has a very small glow, without doing anything.(this relay pba has 2x status leds) can i assume the following, that the pin gets the correct state, when being told what to do so from the script (else a small voltage on the pin if unused.)

, any idea? Not using it that way now RPI supplies the ground and power .
but that is my plan to use it as the final build.dJ5wKNh

(tonertiffi) #75

The end goal, so far all this is working 100%, thanks to allot of help from @pb66

(tonertiffi) #76

Hi @pb66 sorry for asking you again, I have acquired a 20x4 lcd I2c, it updates a hole lot quicker than the 16x2 for some strange reason. Sorry my question would i be able to use the extra 2 lines to display values.

I assume you have to alter, home/emonpi/lcd/

# MQTT Settings
# ------------------------------------------------------------------------------------
mqtt_user = config.get('mqtt','mqtt_user')
mqtt_passwd = config.get('mqtt','mqtt_passwd')
mqtt_host = config.get('mqtt','mqtt_host')
mqtt_port = config.getint('mqtt','mqtt_port')
mqtt_emonpi_topic = config.get('mqtt','mqtt_emonpi_topic')
mqtt_feed1_topic = config.get('mqtt','mqtt_feed1_topic')
mqtt_feed2_topic = config.get('mqtt','mqtt_feed2_topic')

# ------------------------------------------------------------------------------------
# Redis Settings
# ------------------------------------------------------------------------------------
redis_host = config.get('redis', 'redis_host')
redis_port = config.get('redis', 'redis_port')
r = redis.Redis(host=redis_host, port=redis_port, db=0)

# ------------------------------------------------------------------------------------
# General Settings
# ------------------------------------------------------------------------------------

# LCD backlight timeout in seconds 0: always on, 300: off after 5 min
backlight_timeout = config.getint('general','backlight_timeout')
default_page = config.getint('general','default_page')

#Names to be displayed on power reading page
feed1_name = config.get('general','feed1_name')
feed2_name = config.get('general','feed2_name')
feed1_unit = config.get('general','feed1_unit')
feed2_unit = config.get('general','feed2_unit')

(tonertiffi) #77

Please tell me its as simple as adding in 2 more feeds :slight_smile:

(tonertiffi) #78

Here are the 2x files i tried to alter but ya no luckemonPiLCD (2).txt (18.9 KB)
emonPiLCD.txt (996 Bytes)