0

I have a question, I'm working in a project where are a necessary getting of values from a DS18B20 I had read this posts from WebIOPi forum:

https://groups.google.com/forum/#!msg/webiopi/KPOGcDwAODE/zSu9rMR4YpUJ

and

http://webiopi.trouch.com/Tutorial_Devices.html

If I remove the # to a sensor name from the config file and refresh the web page crashes and I don't know what's the cause and how can I fix it?

Hence, I'm trying to do it as you write above without modify the config file, so this is my code...

script.py

import webiopi
from webiopi.devices.sensor.onewiretemp import DS18B20

GPIO=webiopi.GPIO

Temp0=DS18B20
TEMP=4

CONTROL=25
LEFTROT=24
RIGHTROT=23

varTemp=0

@webiopi.macro
def getTemp():
        varTemp="%.2f%" %(Temp0.getCelsius())
        varTemp="Hello"
        return varTemp

@webiopi.macro
def openGreenhouse():
    GPIO.digitalWrite(RIGHTROT,GPIO.HIGH)
    GPIO.digitalWrite(LEFTROT,GPIO.LOW)
    GPIO.digitalWrite(CONTROL,GPIO.HIGH)
    webiopi.sleep(4)
    GPIO.digitalWrite(CONTROL,GPIO.LOW)


@webiopi.macro
def closeGreenhouse():
    GPIO.digitalWrite(RIGHTROT,GPIO.LOW)
    GPIO.digitalWrite(LEFTROT,GPIO.HIGH)
    GPIO.digitalWrite(CONTROL,GPIO.HIGH)
    webiopi.sleep(4)
    GPIO.digitalWrite(CONTROL,GPIO.LOW)


def setup():
    GPIO.setFunction(CONTROL,GPIO.OUT)
    GPIO.setFunction(LEFTROT,GPIO.OUT)
    GPIO.setFunction(RIGHTROT,GPIO.OUT)
    GPIO.setFunction(TEMP,GPIO.IN)
    GPIO.digitalWrite(CONTROL,GPIO.LOW)

def loop():
        webiopi.sleep(1)


def destroy():
    GPIO.digitalWrite(CONTROL,GPIO.LOW)

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Test Button GPIO |18 Enero Carlos Hdz</title>
    <script type="text/javascript" src="/webiopi.js"></script>
    <script type="text/javascript">

    webiopi().ready(function() {

    var flag=true;

    var openGreenHouseButton=webiopi().createButton("openGhButton","Open",function(){
        if(flag===true){
            document.getElementById("openGhButton").innerHTML="Close";
            flag=false;
            webiopi().callMacro("openGreenhouse");

        }
        else{
            document.getElementById("openGhButton").innerHTML="Open";
            flag=true;
            webiopi().callMacro("closeGreenhouse");
        }
    });

    setInterval(callMacro_getTemp,5000);

    $("#controls").append(openGreenHouseButton);


    });

    function callMacro_getTemp(){
       webiopi().callMacro("getTemp",[],getTempCallback);
    }

    function getTempCallback(macro,args,data){
      $("#pTemp").text("hola" + ".");
    }   

    webiopi().refreshGPIO(true);

    </script>
    <style type="text/css">
        button {
            display: block;
            margin: 5px 5px 5px 5px;
            width: 160px;
            height: 120px;
            font-size: 24pt;
            font-weight: bold;
            color: White;
        }
    </style>
</head>
<body>
    <p align="center">Control of Automatic Greenhouse</p>
    <div id="controls" align="center"></div>
    <div align="center" style="color:#0000FF">
     Temperature: <p id="pTemp"></p>
     Level of Water: <input type="text"/><br/>
    </div>   
</body>
</html>

The problem is that the value of the temperature didn't show. I guess is the part of the callback of macros but I don't have idea what to do yet?

May I ask for help??

1

I solved it!!

I reconnected everything and made a search where I found that the last update of Raspbian changed the device tree and you have to enable it so:

1.- Modify the /boot/config.txt in your RPi.

dtoverlay=w1-gpio,gpiopin=<4>

2.-Enable I2C, SPI and Device Tree.

raspi-config

3.- Command these:

modprobe w1-gpio

modprobe w1-therm
cd /sys/bus/w1/devices
ls
//you have to see more than one sentence (we select a slave omit the master setence, for example:)
cd 28-01157362d7ff
cat w1-slave

So next we need to change the config file of WebIOPi:

sudo /etc/webiopi/config

and enable:

temp3=DS18B20 slave: 28-01157362d7ff

And that's it, solved :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.