how to create a button that displays the value temp2

8,629 views
Skip to first unread message

Aurelien aurel

unread,
Aug 19, 2013, 11:28:21 AM8/19/13
to web...@googlegroups.com
HI everyone 
how to create a button that displays the value temp2

I'm newbie on raspberry pi and dev, thank you to erik for his hard work.
I created on my index.html page button to control the gpio and it's works very well but but I must go to the Device Monitor page to display the values ​​of  sensor one wire.
I want to create a button after the other to display values of  temp0  ​​temp1, ...
thank you for your help

Toshi Bass

unread,
Aug 19, 2013, 7:20:46 PM8/19/13
to web...@googlegroups.com
Hi Aurelien

To add button that displays your temperature temp0  and temp1 do the following:-     (note* I assume you don't have any macro already name macro 2 or 3,
                                                                                                                                                          if you do change macro 2 and  3 here to say 6 and 7 or something.....)

in your index.html file after the last button you made make these two new buttons:-

// create a button which call Temp0
              button = webiopi().createButton("macro2", "Temperature", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro2", "Temp"); //set color state

// create a button which call Temp1
              button = webiopi().createButton("macro3", "Temperature", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro3", "Temp"); //set color state

In the next section after existing functions add the following :-

function callMacro_Temp(){
var args = [0, 1]
webiopi().callMacro("Temp", args, macro_Temp_Callback);}
function macro_Temp_Callback(macro, args, data){
temp0 = data.split(" ")[0];
temp1 = data.split(" ")[1];
webiopi().setLabel("macro2", "temp0 " + temp0 +" c");
webiopi().setLabel("macro3", "temp1 " + temp1 +" c");}
setInterval ("callMacro_Temp()", 6000);{
       }

in the <script> section after  
input[type="range"] {
display: block;
width: 160px;
height: 45px;
}
Add the following :-

 .Temp { background-color: Yellow;
                        display: block; 
margin: 5px 5px 5px 5px; 
width: 129px; 
height: 40px;
border-radius:10px;
font-size: 10pt; 
font-weight: 600; }

After you may need to change some these parameters to match your existing buttons!

In script.py make sure you have already the following to get the temperatures into script.py:-

from webiopi.devices.sensor import DS18B20
Temp0 = DS18B20(slave="28-0000045328a0") # put in your specific sensor codes 
Temp1 = DS18B20(slave="28-000004de52e9") # here these are my ones yours will be different.

Then add the following new macro down the bottom after any other macro's.

@webiopi.macro
def Temp(arg0, arg1):
    return ("%s %s" % (temp0, temp1))  

As the temperatures change the value on the buttons will change, no need to update your page.

Hope to helps ...

ToshiBass

Aurelien aurel

unread,
Sep 5, 2013, 4:43:01 PM9/5/13
to web...@googlegroups.com
Hi ToshiBass

Thank you for your help

but my index.html does not work after adding macro.

here is my index.html :

Can you check it, because I'm newbie in html and jscript




<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">
    <meta name="viewport" content="height = device-height, width = 420, user-scalable = no">
    <title>AUREL'S HOME BOX LIGHT</title>
  </head>
  <body>
    <script type="text/javascript" src="/webiopi.js"></script>
    <script type="text/javascript">
        webiopi().ready(function() {
                var content, button;
                content = $("#content");
 w().refreshGPIO(true);
               
        
                // create a "ambiance bassin" labeled button for GPIO 2
                button = webiopi().createGPIOButton(2, "ambiance bassin");
                content.append(button); // append button to content div
                               
                // create a "cascade bassin" labeled button for GPIO 3
                button = webiopi().createGPIOButton(3, "cascade bassin");
                content.append(button); // append button to content div
                
 // create a "Projecteur bassin" labeled button for GPIO 17
                button = webiopi().createGPIOButton(17, "Projecteur bassin");
                content.append(button); // append button to content div
                
 // create a "scarecrow" labeled button for GPIO 18
                button = webiopi().createGPIOButton(18, "scarecrow");
                content.append(button); // append button to content div
               
                // create a "Caisson de basse" labeled button for GPIO 27
                button = webiopi().createGPIOButton(27, "Caisson de basse");
                content.append(button); // append button to content div
       
   // create a "Spot terrasse" labeled button for GPIO 22
                button = webiopi().createGPIOButton(22, "Spot terrasse");
                content.append(button); // append button to content div
                               
                // create a "Lumieres jardin" labeled button for GPIO 23
                button = webiopi().createGPIOButton(23, "Lumieres jardin");
                content.append(button); // append button to content div

  // create a "projecteur terrasse" labeled button for GPIO 24
                button = webiopi().createGPIOButton(24, "projecteur terrasse");
                content.append(button); // append button to content div

 // create a button which call Temp0
                button = webiopi().createButton("macro2", "Temperature", callMacro_Temp);
        content.append(button); // append button to content div
        webiopi().setClass("macro2", "Temp"); //set color state

 // create a button which call Temp1
                button = webiopi().createButton("macro3", "Temperature", callMacro_Temp);
        content.append(button); // append button to content div
        webiopi().setClass("macro3", "Temp"); //set color state  
  }

  function callMacro_Temp(){
 var args = [0, 1]
webiopi().callMacro("Temp", args, macro_Temp_Callback);}
        function macro_Temp_Callback(macro, args, data){
 temp0 = data.split(" ")[0];
 temp1 = data.split(" ")[1];
 webiopi().setLabel("macro2", "temp0 " + temp0 +" c");
 webiopi().setLabel("macro3", "temp1 " + temp1 +" c");}
 setInterval ("callMacro_Temp()", 6000);{

});
        
    </script>
    <style type="text/css">
                button {
                        display: block;
                        margin: 5px 5px 5px 5px;
                        width: 320px;
                        height: 45px;
                        font-size: 24pt;
                        font-weight: bold;
                        color: black;
                 
 }
         input[type="range"] {
                        display: block;
                        width: 160px;
                        height: 45px;
                }
    </style>
    <div id="content" align="center"></div>
  
  <h2><a href="/app/devices-monitor">Temperature bassin</a></h2>
  <h2><a href="/app/gpio-header">pin header</a></h2>
 </body>
</html>


Toshi Bass

unread,
Sep 5, 2013, 5:47:10 PM9/5/13
to web...@googlegroups.com

Hi Aurelien

It doesn't take much to stop a  web page loading, if your using chrome as your web browser try going to the Customize & Control icon - Tools - JavaScript console .. this will help you track-down problems, 

Anyway very simple mistake as follows:-

    }     <-This is incorrect replace with   }); 

               function callMacro_Temp(){
 var args = [0, 1]
webiopi().callMacro("Temp", args, macro_Temp_Callback);}
        function macro_Temp_Callback(macro, args, data){
 temp0 = data.split(" ")[0];
 temp1 = data.split(" ")[1];
 webiopi().setLabel("macro2", "temp0 " + temp0 +" c");
 webiopi().setLabel("macro3", "temp1 " + temp1 +" c");}
 setInterval ("callMacro_Temp()", 6000);{

});    <- This is incorrect replace with   } 
 
     That's it, I ran it and your page is working with these 2 changes above.

Regards

Toshi 

Aurelien aurel

unread,
Sep 6, 2013, 3:22:40 PM9/6/13
to web...@googlegroups.com
Hi ToshiBass

Thank you again.

with the correct syntax web page correctly displays both temperature Bouttons does not display values.

I can not find where the bug.

this my script:

# Imports
import webiopi
import time
from webiopi.devices.sensor import DS18B20

# Enable debug output
webiopi.setDebug()

#sondes temperature
Temp0 = DS18B20(slave="28-0000047ecc2b")
Temp1 = DS18B20(slave="28-00000519193b")

@webiopi.macro
def Temp(arg0, arg1):
    return ("%s %s" % (Temp0, Temp1)) 
  
and this is my index.html:

                button = webiopi().createButton("macro2", "temp bassin", callMacro_Temp);
        content.append(button); // append button to content div
        webiopi().setClass("macro2", "Temp"); //set color state

 // create a button which call Temp1
                button = webiopi().createButton("macro3", "Temp garage", callMacro_Temp);
        content.append(button); // append button to content div
        webiopi().setClass("macro3", "Temp"); //set color state  
  });

  function callMacro_Temp(){
 var args = [0, 1]
webiopi().callMacro("Temp", args, macro_Temp_Callback);}
        function macro_Temp_Callback(macro, args, data){
 temp0 = data.split(" ")[0];
 temp1 = data.split(" ")[1];
 webiopi().setLabel("macro2", "temp0 " + temp0 +" c");
 webiopi().setLabel("macro3", "temp1 " + temp1 +" c");}
 setInterval ("callMacro_Temp()", 6000);{

}
        
    </script>
    <style type="text/css">
                button {
                        display: block;
                        margin: 5px 5px 5px 5px;
                        width: 320px;
                        height: 45px;
                        font-size: 24pt;
                        font-weight: bold;
                        color: black;
                 
 }
         .Temp { background-color: Yellow;
                        display: block; 
  margin: 5px 5px 5px 5px; 
  width: 320px; 
  height: 40px;
  border-radius:10px;
  font-size: 10pt; 
  font-weight: 600;
                }

Toshi Bass

unread,
Sep 6, 2013, 4:49:08 PM9/6/13
to web...@googlegroups.com
Hi Aurelien

I have pasted your code into a index html and it works perfectly see attached so we can discount a problem with index.html your macro is also correct it works perfectly so we now need to check if you are getting the temperature values into the python script so -


@webiopi.macro
def Temp(arg0, arg1):
    print Temp0, Temp1                                <- add this line into the macro and save
    return ("%s %s" % (Temp0,Temp1))

start webiopi with the debug command   sudo webiopi -c /etc/webiopi/config and open the webpage 

check the debug screen you should be seeing a continuous stream on information and in that you should be able to see the temperatures printed followed by POST /macros/Temp/0,1 with HTTP/1.1" 200 - which means it posted successfully. 

2013-09-06 21:32:53 - HTTP - DEBUG - "GET /* HTTP/1.1" 200 -
2013-09-06 21:32:53 - HTTP - DEBUG - "GET /* HTTP/1.1" 200 -
2013-09-06 21:32:55 - HTTP - DEBUG - "GET /* HTTP/1.1" 200 -
2013-09-06 21:32:55 - HTTP - DEBUG - "GET /* HTTP/1.1" 200 -
2013-09-06 21:32:57 - HTTP - DEBUG - "GET /* HTTP/1.1" 200 -
37.38 12.00
2013-09-06 21:32:57 - HTTP - DEBUG - "POST /macros/Temp/0,1 HTTP/1.1" 200 -

If you are not getting the above it means that your script is not getting the temperatures so double check and confirm that - are listed config file 
Temp0 = DS18B20(slave="28-0000047ecc2b")
Temp1 = DS18B20(slave="28-00000519193b")
Temp0 = DS18B20(slave="28-0000047ecc2b")
Temp1 = DS18B20(slave="28-00000519193b")
 
are listed config file

The only other thing I can suggest is that you add the following in the imports section (like after  import webiopi  etc)of your script.py file   :-

sys.path.append("/home/pi/webiopi/htdocss")        <- this need to be your path to where your index.html and you python script are located I seam to remember this being a problem I uncounted, let me know how you get on.

Hope it helps

Toshi. 


Capture.JPG

Toshi Bass

unread,
Sep 6, 2013, 4:56:17 PM9/6/13
to web...@googlegroups.com
Sorry slight typing mistake - should read 

If you are not getting the above it means that your script is not getting the temperatures so double check and confirm that - 
Temp0 = DS18B20(slave="28-0000047ecc2b")
Temp1 = DS18B20(slave="28-00000519193b")
 
are listed your config file

Didn't want to confuse you more than your already confused hahahah

Toshi

Aurelien aurel

unread,
Sep 9, 2013, 3:22:41 PM9/9/13
to web...@googlegroups.com
Hi ToshiBass

Thank you for your patience,

But when i add "print Temp0,Temp1" in my script and lunch webiopi -c /etc/webiopi/config the debug say that :
SyntaxError: invalid syntax at line 16.

and stop !!!!!!!!


Aurelien aurel

unread,
Sep 9, 2013, 3:45:27 PM9/9/13
to web...@googlegroups.com
without the line "Max printing ..." in script.py
webiopi when a start debugging says "Post macros/temp/0, 1 http / 1.1 200"
why its not working?????

Toshi Bass

unread,
Sep 9, 2013, 5:32:13 PM9/9/13
to web...@googlegroups.com
Hi again Aurelien,

Believe me we will get this working, however I need you to be clear first 

The line to add is    print temp0, temp1   do not add " "   

You need this line in so we can check if the temperatures are being posted it may say Post macros/temp/0, 1 http / 1.1 200 but we need to know what values it posted.

Did you double double check that the 2 sensor Temp0 = DS18B20(slave="28-0000047ecc2b")   Temp1 = DS18B20(slave="28-00000519193b") are exactly the same as you put in the config file      etc/webiopi/config

If it still does not work change to this to see what you get :-

@webiopi.macro
def Temp(arg0, arg1):
    return ("%s %s" % (2222,33333))

Dont forget to save, stop the script file and restart it and refresh the web page each time you make a change, let me know result.

Toshi

Toshi Bass

unread,
Sep 9, 2013, 6:08:45 PM9/9/13
to web...@googlegroups.com
Aurelien,

Hmmmm I made big mistake, you are missing 2 lines of code please accept my apology, you need to change the first 2 lines and add the second 2 lines :-

temp0 = DS18B20(slave="28-0000047ecc2b")                    <-- Change T for t in Temp0
temp1 = DS18B20(slave="28-00000519193b")                   <-- Change T for t in Temp1

Temp0 = "%.2f" % (temp0.getCelsius())                                 <-- after Add this line
Temp1 = "%.2f" % (temp1.getCelsius())                                 <-- and this

sorry about that

Regards Toshi.

Jay Lang

unread,
Sep 10, 2013, 11:17:14 AM9/10/13
to web...@googlegroups.com
Wow crazy
thanks for your guys work but i got it going, and for my own future referance this is what i got.( all credit to toshi)

index.html edit:
under your last button and before  }); add:


                // create a button which call Temp0
              button = webiopi().createButton("macro2", "Temperature", callMacro_Temp);
              content.append(button); // append button to content div
              webiopi().setClass("macro2", "Temp"); //set color state

                // create a button which call Temp1
              button = webiopi().createButton("macro3", "Temperature", callMacro_Temp);
              content.append(button); // append button to content div
              webiopi().setClass("macro3", "Temp"); //set color state

then after the  }); and before the </script> add:
function callMacro_Temp(){
                var args = [0, 1]
                webiopi().callMacro("Temp", args, macro_Temp_Callback);}
        function macro_Temp_Callback(macro, args, data){
                temp0 = data.split(" ")[0];
                temp1 = data.split(" ")[1];
                webiopi().setLabel("macro2", "temp0 " + temp0 +" c");
                webiopi().setLabel("macro3", "temp1 " + temp1 +" c");}
                setInterval ("callMacro_Temp()", 6000);{
       }

then after                 input[type="range"] {
                        display: block;
                        width: 200px;
                        height: 90px;
                }

##in the script section add:

                  .Temp {
                        background-color: Yellow;
                        display: block;
                        margin: 5px 5px 5px 5px;
                        width: 129px;
                        height: 40px;
                        border-radius:10px;
                        font-size: 10pt;
                        font-weight: 600;
                 }


then in your /etc/webiopi/config under the device section add:
Temp0 = DS18B20 slave:28-000004d112ef   #<<change the device id
Temp1 = DS18B20 slave:28-00000513b3df    #<<change the device id

also uncomment the myscript and point to your script so it starts when the server is started:
myscript = /home/pi/WebIOPi-0.6.0/htdocs/app/pigrow/script.py  #make sure the path is right

and then in your script.py(should be located with the index.html i think) - make sure it is chmod 755 to run:


# Imports
import webiopi
import time
from webiopi.devices.sensor import DS18B20
#sys.path.append("/home/pi/WebIOPi-0.6.0/htdocs/app/pigrow/")
# Enable debug output
webiopi.setDebug()

#sondes temperature
Temp0 = DS18B20 (slave="28-000004d112ef")
Temp1 = DS18B20 (slave="28-00000513b3df")
Temp0 = "%.2f" % (Temp0.getCelsius())
Temp1 = "%.2f" % (Temp1.getCelsius())

@webiopi.macro
def Temp(arg0, arg1):
    return ("%s %s" % (Temp0, Temp1))





Jay Lang

unread,
Sep 10, 2013, 11:29:09 AM9/10/13
to web...@googlegroups.com
and dont forget to restart the webiopi after your changes or when ever you change the your script.py

Jay Lang

unread,
Sep 10, 2013, 3:21:47 PM9/10/13
to web...@googlegroups.com
how do i strip off the last digits for when i get it in "F"
thanks

Robert More

unread,
Sep 10, 2013, 3:32:30 PM9/10/13
to web...@googlegroups.com
What method did you use to convert to F* ?

Jay Lang

unread,
Sep 10, 2013, 4:55:16 PM9/10/13
to web...@googlegroups.com
in your script.py change .getcelcius to .getFahrenheit
(Temp0.getFahrenheit())

Jay Lang

unread,
Sep 10, 2013, 7:37:37 PM9/10/13
to web...@googlegroups.com
i added about 9 sensors.
they all refresh 1 time, then will not refresh again untill the server is restarted.
i do not believe they were refreshing before i added more.
any one getting refresh?
thanks

Jay Lang

unread,
Sep 10, 2013, 8:06:57 PM9/10/13
to web...@googlegroups.com
if it means anything, if i restart the web server all browsers with open page update.

Toshi Bass

unread,
Sep 11, 2013, 12:50:26 PM9/11/13
to web...@googlegroups.com
Hi Jay,

The 2 in    %.2f" % in the line Temp0 = "%.2f" % (Temp0.getCelsius())     is the number  of decimal places - - so  Temp0= "%.0f" % (Temp0.getFahrenheit()) would give no decimal places.

Regarding refreshing temperatures you just need to move -

Temp0 = "%.2f" % (Temp0.getCelsius())
Temp1 = "%.2f" % (Temp1.getCelsius())

into the loop then each time webiopi loops it will update the temp's as follows :-

(or you can  refresh the variables by moving the lines inside the macro if you want, but you then need to make the variables global.)

# Looped by WebIOPi
def loop():
    # Toggle LED each 5 seconds
    value = not GPIO.digitalRead(LED1)
    GPIO.digitalWrite(LED1, value)
    Temp0 = "%.2f" % (Temp0.getCelsius())
    Temp1 = "%.2f" % (Temp1.getCelsius())
    webiopi.sleep(5)      



 I also have multiple sensors however I found that there was quite a delay each time all the sensors were checked at once and also for some reason I get a random error sometimes when reading the sensors so to get over any error and reduce the processing delay / smooth out the loop,  I check 1 sensor each loop, so for instance if you had 6 sensors, -

#---------------------------------------------------------------
from webiopi.devices.sensor import DS18B20
temp0 = DS18B20(slave="28-00000xxxxxxx")        #<-- Change xxxxxxx to you sensor numbers, note* my sensors are called temp0, temp1, temp2, etc in the config file
temp1 = DS18B20(slave="28-00000xxxxxxx")        #<-- not sure its a good idea to have the same variable name twice like  :-
temp2 = DS18B20(slave="28-00000xxxxxxx")        #<-- Temp0 = DS18B20(slave="28-00000xxxxxxx")  and also  Temp0 = "%.2f" % (Temp0.getCelsius())
temp3 = DS18B20(slave="28-00000xxxxxxx") 
temp4 = DS18B20(slave="28-00000xxxxxxx")
temp5 = DS18B20(slave="28-00000xxxxxxx")
#---------------------------------------------------------------
T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5 = 0, 0, 0, 0, 0, 0, 0
#---------------------------------------------------------------
# Looped by WebIOPi
def loop():
    # Toggle LED each 5 seconds
    value = not GPIO.digitalRead(LED1)
    GPIO.digitalWrite(LED1, value)

#Get DS18B20 temperatures one sensor each pass of loop. it will try to get sensor 1 on first pass then 2, 3, 4, 5, then 0,1,2,3,4,5,0,1,2 etc etc 
    if T ==6:
        T = 0
    else:
        T +=1
    if T == 0:  
        try:                 
            Temp0 = "%.2f" % (temp0.getCelsius())
        except (IOError, TypeError):         
    if T == 1:    
        try:
            Temp1 = "%.2f" % (temp1.getCelsius())  
        except (IOError, TypeError):
            pass
    if T == 2: 
        try:
            Temp2 = "%.2f" % (Temp2.getCelsius())
        except (IOError, TypeError):
            pass
    if T == 3:  
        try:
            Temp3 = "%.2f" % (temp4.getCelsius())
        except (IOError, TypeError):
            pass
    if T == 3: 
        try:
            Temp4 = "%.2f" % (temp3.getCelsius())
        except (IOError, TypeError):
            pass
    if T == 4: 
        try:
            Temp4 = "%.2f" % (temp4.getCelsius())
        except (IOError, TypeError):
            pass 
    if T == 5: 
        try:
           Temp5 = "%.2f" % (temp5.getCelsius())
        except (IOError, TypeError):
            pass

    webiopi.sleep(3)      
#---------------------------------------------------------------

@webiopi.macro
def Temp(arg0, arg1,arg2,arg3,arg4,arg5):
    return ("%s %s %s %s %s %s" % (Temp0, Temp1, Temp2, Temp3, Temp4, Temp5))



Hope it helps 
Toshi Bass

Jay Lang

unread,
Sep 12, 2013, 7:37:59 PM9/12/13
to web...@googlegroups.com
thanks, but im still not refreshing. i do have my sensors label differently then yours but can always get the initial temp.
tomorrow night ill rename all mine into your naming convention and give it a try.

could you possable give me a example on how to use:
HTTP GET /devices/tmp/sensor/temperature/f
thanks for your patients :)
Message has been deleted

Aurelien aurel

unread,
Sep 15, 2013, 5:00:13 PM9/15/13
to web...@googlegroups.com
 HI everyone 

The script runs, the refresh java script is good, but the value are not really  refreshes:

temp0 = DS18B20 (slave = "28-00000518a744")
temp1 = DS18B20 (slave = "28-00000519193b")
Temp0 = "% .2 f"% (temp0.getCelsius ())
Temp1 = "% .2 f"% (temp1.getCelsius ())

Temp0, 1 are fixed at launch but is not updated in the python script.

Thank You
We can do it

Toshi Bass

unread,
Sep 16, 2013, 6:57:02 PM9/16/13
to web...@googlegroups.com
Aurelien,

One more time for clarity.

Python script to look like this :-


# Imports
import webiopi

# Enable debug output
webiopi.setDebug()

# Retrieve GPIO lib
GPIO = webiopi.GPIO

from webiopi.devices.sensor import DS18B20
temp0 = DS18B20(slave="28-00000XXXXXXX")     #<- Your Sensor ID's
temp1 = DS18B20(slave="28-00000XXXXXXX")     #<-

LED1   = 25

# Called by WebIOPi at script loading
def setup():
    webiopi.debug("Script with macro - Setup")
    # Setup GPIOs

    GPIO.setFunction(LED1, GPIO.OUT)
    

# Looped by WebIOPi
def loop():
    # Toggle LED each 5 seconds
    value = not GPIO.digitalRead(LED1)
    GPIO.digitalWrite(LED1, value)

    Temp0 = "%.2f" % (temp0.getCelsius())   # <-- put these two lines here
    Temp1 = "%.2f" % (temp1.getCelsius())  # <--

    webiopi.sleep(5)        

# Called by WebIOPi at server shutdown
def destroy():
    webiopi.debug(Script with macro - Destroy")
    GPIO.setFunction(LED1, GPIO.IN)

@webiopi.macro
def Temp(arg0, arg1):
    return ("%s %s" % (temp0, temp1))
_______________________________________

Start webiopi with the debug command   sudo webiopi -c /etc/webiopi/config    and open the webpage and check the temperatures on the two buttons.

Check the terminal and look for the following lines

37.38 22.02
2013-09-06 21:32:57 - HTTP - DEBUG - "POST /macros/Temp/0,1 HTTP/1.1" 200 -

37.38 & 22.02 are my temp readings yours will be different but should be there in the scrolling terminal window every (6000 set by the line setInterval ("callMacro_Temp()", 6000);{ in the index.html) increase the temperature of one of the sensors, after a time (reaction time of the DS18B20 sensor) keep checking the terminal window, you should see the temperature increase.

Assuming you see this it proves that the Python side is working correctly. so then check the web page you should see also the temperatures have changed, increase the temperature of the sensor again and check that the temperature on the button changes if not then the fault is in the index.html file, post the file and I will check it, best of luck.

Toshi Bass

Aurelien aurel

unread,
Sep 17, 2013, 3:39:25 PM9/17/13
to web...@googlegroups.com
HI Toshi Bass

When I moves the two lines temp0 webiopi script pyton don't work :
  
File "/usr/share/webiopi/htdocs/script.py", line 27, in Temp
    return ("%s %s" % (Temp0, Temp1))
NameError: global name 'Temp0' is not defined

my script:

# Imports
import webiopi
import time
from webiopi.devices.sensor import DS18B20


#sys.path.append("/home/pi/WebIOPi-0.6.0/htdocs")

# Enable debug output
webiopi.setDebug()

#sondes temperature
temp0 = DS18B20 (slave="28-00000518a744")
temp1 = DS18B20 (slave="28-00000519193b")



# Looped by WebIOPi
def loop():
Temp0 = "%.2f" %(temp0.getCelsius())
Temp1 = "%.2f" %(temp1.getCelsius())
webiopi.sleep(5)


@webiopi.macro
def Temp(arg0, arg1):
return ("%s %s" % (Temp0, Temp1))

thank you

Toshi Bass

unread,
Sep 17, 2013, 6:50:18 PM9/17/13
to web...@googlegroups.com
Hi Aurelien,

Try this, I have tested it with your index.html file from previous post it works fine.

# Imports
import webiopi
import time
import sys
sys.path.append("/home/pi/webiopi/htdocss")

# Enable debug output
webiopi.setDebug()

from webiopi.devices.sensor import DS18B20
temp0 = DS18B20(slave="28-00000518a744")
temp1 = DS18B20(slave="28-00000519193b")

@webiopi.macro
def Temp(arg0, arg1):
    try:
       Temp0 = "%.2f" % (temp0.getCelsius())
    except (IOError, TypeError):
        Temp0 = 0
        pass
    try:
        Temp1 = "%.2f" % (temp1.getCelsius())
    except (IOError, TypeError):
        Temp1 = 0
        pass
    print Temp0, Temp1
    return ("%s %s" % (Temp0, Temp1))

I apologize for all the changes, understand the my script file is 1000+ lines of code with allot of things happening 
so its quite difficult to pull just one small part out in its entirety, so most of of the suggestions have been from my head.

I have added simple error checking because I get quite a few errors from my sensors, when you run this code if you also get alot of
zero readings I would appreciate you telling me as I want to understand if its normal for B20 sensors to have these errors or if its my wiring.

If you get a lot of zero's I will put together a some code to check for zero and use the last reading instead of returning 0.

Toshi

Aurelien aurel

unread,
Sep 18, 2013, 2:18:47 PM9/18/13
to web...@googlegroups.com

HI Toshi Bass

big thank you to you, it works very well.

I haven't got  "zero" for the monent.

Your personal project seems very successful, did you do a tutorial for share your experience?

as I am very beginner in python I am looking for examples of code to improve my webiopi.

Toshi Bass

unread,
Sep 18, 2013, 7:01:00 PM9/18/13
to web...@googlegroups.com
Hi Aurelien,

Thanks for your response, so happy you managed to get this working in the end, it was beginning to bug me, guess I need to go check my wiring now,
I am also beginner I just began 3 months before you did, personal project is work in progress its all been trial and error, one day I may see
light at the end of the tunnel, 

Toshi  

Jay Lang

unread,
Sep 21, 2013, 4:37:23 PM9/21/13
to web...@googlegroups.com

thanks a bunch guys, 
working good, get a zero sometimes but not a biggy, i know sometimes the sensors do not answer all the time

Jay Lang

unread,
Sep 23, 2013, 6:11:46 PM9/23/13
to web...@googlegroups.com

unfortunately the script with 9 sensors bogs the web server and the page is almost unresponsive. hardly any load on the cpu, seems the update of the temps dictates the page.

Toshi Bass

unread,
Sep 24, 2013, 9:26:56 AM9/24/13
to web...@googlegroups.com


Hi Jay,

I assume you followed the post to Aurelien and just added  7 more sensors, however I told in previous post that if you "have multiple sensors, I found that there was quite a delay each time all the sensors were checked at once -  to reduce the processing delay / smooth out the loop,  I check 1 sensor each loop, " (incidentally when I said processing i meant "fetching the values" nothing to do with cpu processor load ) so no surprise 9 sensors bogs your web server.

You simply need to arrange that 1 (or maybe 2) of your 9 sensor is checked each time the macro runs and then the next time a different sensor is checked.

So for you and anyone else following this post: a revised code for doing that based on Aureliens working code:-

script.py

# Imports
import webiopi
import time
import sys
sys.path.append("/home/pi/webiopi/htdocss")  #<--- or whatever your path is !

# Enable debug output
webiopi.setDebug()

from webiopi.devices.sensor import DS18B20
temp0 = DS18B20(slave="28-00000XXXXXXX")  #< -- your sensor numbers go here, that are designated in the config file 
temp1 = DS18B20(slave="28-00000XXXXXXX")
temp2 = DS18B20(slave="28-00000XXXXXXX")
temp3 = DS18B20(slave="28-00000XXXXXXX")
temp4 = DS18B20(slave="28-00000XXXXXXX")
temp5 = DS18B20(slave="28-00000XXXXXXX")
temp6 = DS18B20(slave="28-00000XXXXXXX")
temp7 = DS18B20(slave="28-00000XXXXXXX")
temp8 = DS18B20(slave="28-00000XXXXXXX")


global T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8
T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8 = 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0
 



def get_DS18B20_Temperature():
    global T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8
    if T == 9:
        T = 0
    print T
    try:
        if T == 0:
            Temp0 = "%.2f" % (temp0.getCelsius())
        if T == 1:    
            Temp1 = "%.2f" % (temp1.getCelsius())  
        if T == 2: 
            Temp2 = "%.2f" % (temp2.getCelsius())
        if T == 3:  
            Temp3 = "%.2f" % (temp4.getCelsius())
        if T == 4: 
            Temp4 = "%.2f" % (temp3.getCelsius())
        if T == 5: 
            Temp5 = "%.2f" % (temp5.getCelsius())
        if T == 6: 
            Temp6 = "%.2f" % (temp6.getCelsius())
        if T == 7: 
            Temp7 = "%.2f" % (temp7.getCelsius())
        if T == 8: 
            Temp8 = "%.2f" % (temp8.getCelsius())
        T +=1
        print Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8
        return Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8
    except (IOError, TypeError):
        print"ERROR getting temp", T
        T +=1    # remove this line if you want to retry the same sensor that produced an error again next time.
        pass




@webiopi.macro
def Temp(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8):
    get_DS18B20_Temperature() 
    return ("%s %s %s %s %s %s %s %s %s" % (Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8))

add this to index.html after existing buttons


      // create a macro button which call Temp
              button = webiopi().createButton("macro0", "temp 0 = ", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro0", "Temp"); //set color state

              button = webiopi().createButton("macro1", "temp 1 = ", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro1", "Temp"); //set color state

              button = webiopi().createButton("macro2", "temp 2 = ", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro2", "Temp"); //set color state

              button = webiopi().createButton("macro3", "temp 3 = ", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro3", "Temp"); //set color state

              button = webiopi().createButton("macro4", "temp 4 = ", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro4", "Temp"); //set color state

              button = webiopi().createButton("macro5", "temp 5 = ", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro5", "Temp"); //set color state

              button = webiopi().createButton("macro6", "temp 6 = ", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro6", "Temp"); //set color state

              button = webiopi().createButton("macro7", "temp 7 = ", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro7", "Temp"); //set color state

              button = webiopi().createButton("macro8", "temp 8 = ", callMacro_Temp);
      content.append(button); // append button to content div
      webiopi().setClass("macro8", "Temp"); //set color state

      webiopi().refreshGPIO(true);

   });

   function callMacro_Temp(){
  var args = [0, 1, 2, 3, 4, 5, 6, 7, 8]
webiopi().callMacro("Temp", args, macro_Temp_Callback);}
         function macro_Temp_Callback(macro, args, data){
  temp0 = data.split(" ")[0];
  temp1 = data.split(" ")[1];
  temp2 = data.split(" ")[2];
  temp3 = data.split(" ")[3];
  temp4 = data.split(" ")[4];
  temp5 = data.split(" ")[5];
  temp6 = data.split(" ")[6];
  temp7 = data.split(" ")[7];
  temp8 = data.split(" ")[8];

  webiopi().setLabel("macro0", "temp0 " + temp0 +" c");
  webiopi().setLabel("macro1", "temp1 " + temp1 +" c");
  webiopi().setLabel("macro2", "temp2 " + temp2 +" c");
  webiopi().setLabel("macro3", "temp3 " + temp3 +" c");
  webiopi().setLabel("macro4", "temp4 " + temp4 +" c");
  webiopi().setLabel("macro5", "temp5 " + temp5 +" c");
  webiopi().setLabel("macro6", "temp6 " + temp6 +" c");
  webiopi().setLabel("macro7", "temp7 " + temp7 +" c");
  webiopi().setLabel("macro8", "temp8 " + temp8 +" c");}

  setInterval ("callMacro_Temp()", 4000);{

}
        
    </script>

    <style type="text/css">

          button {         display: block;
                                margin: 5px 5px 5px 5px;
                                width: 320px;
                                height: 45px;
                                font-size: 24pt;
                                font-weight: bold;
                                color: black;
  }

       .Temp { background-color: Yellow;
                               display: block; 
       margin: 5px 5px 5px 5px; 
       width: 120px; 
       height: 40px;
       border-radius:10px;
       font-size: 10pt; 
       font-weight: 600; 
                }

    </style>

   <body>
          <div id="content" align="left"></div>
   </body>

</html>


Toshi
 

Shelburne Fire

unread,
Sep 26, 2013, 4:31:21 PM9/26/13
to web...@googlegroups.com
Toshi, thanks for the heads up on the K-type thermocouple connections.  You probably saved me a day of backtracking.

I am now getting an invalid syntax error:

pi@raspberrypi ~ $ sudo webiopi -c /etc/webiopi/config
2013-09-26 16:17:32 - WebIOPi - INFO - Starting WebIOPi/0.6.0/Python3.2
2013-09-26 16:17:32 - WebIOPi - INFO - GPIO - Native mapped to REST API /GPIO
2013-09-26 16:17:32 - WebIOPi - INFO - Loading configuration from /etc/webiopi/config
2013-09-26 16:17:32 - WebIOPi - INFO - Temperature - DS18B20(slave=28-000004d95204) mapped to REST API /devices/temp0
2013-09-26 16:17:32 - WebIOPi - INFO - Temperature - DS18B20(slave=28-000004d95204) mapped to REST API /devices/Tank_Return
2013-09-26 16:17:32 - WebIOPi - INFO - Temperature - DS18B20(slave=28-000004da568c) mapped to REST API /devices/Tank_Top
2013-09-26 16:17:32 - WebIOPi - INFO - Temperature - DS18B20(slave=28-000004a81f51) mapped to REST API /devices/Tank_Supply
2013-09-26 16:17:32 - WebIOPi - INFO - Temperature - DS18B20(slave=28-000004d992d1) mapped to REST API /devices/House_Supply
2013-09-26 16:17:32 - WebIOPi - INFO - Temperature - DS18B20(slave=28-000004d9e659) mapped to REST API /devices/Boiler
2013-09-26 16:17:32 - WebIOPi - INFO - Temperature - DS18B20(slave=28-000004da2d65) mapped to REST API /devices/Modine
2013-09-26 16:17:32 - WebIOPi - INFO - Temperature - DS18B20(slave=28-000004da2d1d) mapped to REST API /devices/House_Return
2013-09-26 16:17:32 - WebIOPi - INFO - Temperature - DS18B20(slave=28-000004d92ef7) mapped to REST API /devices/Tank_Bottom
2013-09-26 16:17:32 - WebIOPi - INFO - Loading myscript from /home/pi/webiopi/examples/scripts/macros/script.py
2013-09-26 16:17:32 - WebIOPi - ERROR - invalid syntax (script.py, line 33)
Traceback (most recent call last):
  File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/__main__.py", line 73, in <module>
    main(sys.argv)
  File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/__main__.py", line 67, in main
    server = Server(port=port, configfile=configfile)
  File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/server.py", line 86, in __init__
    loadScript(name, source, self.restHandler)
  File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/utils.py", line 164, in loadScript
    script = imp.load_source(name, source)
  File "/home/pi/webiopi/examples/scripts/macros/script.py", line 33
    print T
          ^
SyntaxError: invalid syntax

here is my script.py file:

# Imports
import webiopi
import time
import sys
sys.path.append("/home/pi/webiopi/htdocss")  #<--- or whatever your path is !

# Enable debug output
webiopi.setDebug()

from webiopi.devices.sensor import DS18B20
temp0 = DS18B20(slave="28-000004a81f51")  #< -- your sensor numbers go here, that are designated in the config file 
temp1 = DS18B20(slave="28-000004d92ef7")
temp2 = DS18B20(slave="28-000004d95204")
temp3 = DS18B20(slave="28-000004d992d1")
temp4 = DS18B20(slave="28-000004d9e659")
temp5 = DS18B20(slave="28-000004da2d1d")
temp6 = DS18B20(slave="28-000004da2d65")
temp7 = DS18B20(slave="28-000004da568c")



global T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7
T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7 = 0, 0, 0, 0, 0, 0, 0, 0, 0




def get_DS18B20_Temperature():
    global T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7
    if T == 8:
        T = 0
    print T
    try:
        if T == 0:
            Temp0 = "%.2f" % (temp0.getCelsius())
        if T == 1:    
            Temp1 = "%.2f" % (temp1.getCelsius())  
        if T == 2: 
            Temp2 = "%.2f" % (temp2.getCelsius())
        if T == 3:  
            Temp3 = "%.2f" % (temp4.getCelsius())
        if T == 4: 
            Temp4 = "%.2f" % (temp3.getCelsius())
        if T == 5: 
            Temp5 = "%.2f" % (temp5.getCelsius())
        if T == 6: 
            Temp6 = "%.2f" % (temp6.getCelsius())
        if T == 7: 
            Temp7 = "%.2f" % (temp7.getCelsius())
        T +=1
        print Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7
        return Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7
    except (IOError, TypeError):
        print"ERROR getting temp", T
        T +=1    # remove this line if you want to retry the same sensor that produced an error again next time.
        pass




@webiopi.macro
def Temp(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7):
    get_DS18B20_Temperature() 
    return ("%s %s %s %s %s %s %s %s %s" % (Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7))


I modified the script.py file since I have 8 sensors, not 9.   I removed all the Temp8 references, etc.  Did I mess something up that is causing the syntax problem?

On Thursday, September 26, 2013 4:04:22 PM UTC-4, Toshi Bass wrote:
Jim, Great project, all do-able I would say, including adding alarms etc for high / low temperatures, you just need a  K type thermocouple and a MAX31855 Thermocouple Amplifier for the flue, range -200°C to 1350°C , that breakout board connects directly to the raspi spi bus, so if your planning that make sure you don't use gpio 7, 8, 9 ,10,& 11 for anything they are all required to access the spi bus.

Toshi Bass

unread,
Sep 26, 2013, 5:17:49 PM9/26/13
to web...@googlegroups.com
Hi Jim,

You forgot to take out  a %s in the following line:-

    return ("%s %s %s %s %s %s %s %s %s" % (Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7))

Should be like this 8 off temps &  8 off %s 

    return ("%s %s %s %s %s %s %s %s" % (Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7))

obviously in index.html remove everything with instance of 8

Incidentally considering your project if you don't want buttons the fact that you are sending the 8 temperatures from your script.py to the index.html means that you can use that same information in index.html to put the values into a table or whatever, if your interested I could post you some code which I use?

Toshi

Shelburne Fire

unread,
Sep 26, 2013, 5:35:21 PM9/26/13
to web...@googlegroups.com
I made the change on the %s and still get the invalid syntax on line 33 print T

Toshi Bass

unread,
Sep 27, 2013, 12:15:57 PM9/27/13
to web...@googlegroups.com
Jim,  I copied and pasted and ran the script two posts up, (after removing one  %s  for only 8 sensors) everything work fine, for sure line 33 print T is not a syntax error, and if T had no value the error would be T not defined, in reality both print statements in this function are only for testing purpose you can remove them if you like, but I suggest you try copy and pasting the script in again, you could have a whitespace error in yours.

Toshi

Shelburne Fire

unread,
Sep 27, 2013, 1:19:12 PM9/27/13
to web...@googlegroups.com
Thanks, Toshi, I created a new script.py, copied, pasted the code two posts up and ran the debug.  No change. it still says invalid syntax on the print line.  So I commented out the two print lines and ran the debug again.  Then it reminded me that there was a third print line in Line 55 where it said invalid syntax.  I then commented out that line and now the last line of the debug says:

 File "/usr/lib/python3.2/socketserver.py", line 430, in server_bind
    self.socket.bind(self.server_address)
socket.error: [Errno 98] Address already in use

Then I go to port 8000 from a web browser and get:

So I guess that last error message can be ignored?

Now to figure out how to get the temp readings in there.

Answering one of your other questions, yes, I will be interested in code to put the values in a table or even more likely to graph them over time.  But let's take this one step at a time for now ;-).

Thanks again for all your help.

Jim

Toshi Bass

unread,
Sep 27, 2013, 2:04:16 PM9/27/13
to web...@googlegroups.com
Hi Jim,

The last error message means you already have an instance of webiopi already running so your trying to start another instance which is not possible, you have to stop the server or shutdown and restart the pi to clear that.

I don't know how I missed this but the syntax error in print is because you are using Python 3 and I wrote the script using Python 2.7 easy to fix though just make the following changes :-   (Sorry)

 print T    needs to be   print (T)

print Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7    needs to be   print (Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7)

print"ERROR getting temp", T   needs to be  print ("ERROR getting temp"), (T)

Toshi

DavidVT

unread,
Sep 28, 2013, 8:25:12 AM9/28/13
to web...@googlegroups.com
Nice progress here on the temp display. I am also setting up for an outdoor wood boiler that I can monitor from my long distance travels.

Some of my learning curve issues related to the real simple stuff like finally realizing I needed to change the directory name webiopi0.6.0 to webiopi.
Commenting out those two lines in the script was another big help.
I seem to have scrambled my sd card a few times and had all but given up on webiopi until I moved the entire OS to a USB stick. Thus far no fatal crashes have occurred. I remain concerned about where the 1wire modules are writing their temperature data. It would be nice if that was all being done in ram. Anyone know?

I was able to use webiopi in the background with an RRD setup and was able to publish nice graphs for a few days before one of my many fatal sd card crashes.

Now if I could just see an example where a 1wire signal was displayed on a graphic dial all within webiopi. I saw the one graphic example in a thread here but still can't quite connect the dots to make one work or even start. Google is usually my helper but there seems a steep cliff once one gets past the first successful square button.

Any links or thoughts about how to reach the next level of expertise with webiopi especially with regards to fancy graphical displays of data within a browser?

Shelburne Fire

unread,
Sep 28, 2013, 11:12:04 AM9/28/13
to web...@googlegroups.com
thanks, toshi, the 3 vs 2.7 crossed my mind but I didn't know enough about it to be sure.  I see we have another wood boiler guy now.  Maybe we need to start a new thread just for boilers? LOL  Let me clean up the index.html and script.py and I will post them for others to use as starting points.

i think the error message is just going to stay there.  I have webiopi auto loading on boot up.  As long as I know that it only means that things are working, I am happy.

Jim

Toshi Bass

unread,
Sep 28, 2013, 2:04:43 PM9/28/13
to web...@googlegroups.com
Hi Log burners,
Jim,

1. You don't have to live with the error message just because you start webiopi on boot, up just stop webiopi with   sudo /etc/init.d/webiopi stop    then restart with    sudo webiopi -c /etc/webiopi/config   to debug your code, the next time you restart the pi webiopi will start at boot up again.
2. Looking on your error screen several posts up you appear to have added one sensor twice (making 9 sensors) and there in a different order to your script.py although this makes no difference to webiopi I think you may have a bit of a job figuring out which which sensor is which when you try to add descriptions in the index.html file. 
3. Are you getting the temperatures into Index.html on the buttons now and are you ready for installment 2 the table with the temperature in.?

Dave,
1. Dont really understand why your question about ram, the sensors are being read by webiopi or indeed if you want to write some code in python or even in the terminal window you can like send a signal to the sensor using its unique number and it will respond with some figure, convert that and you have the temperature I guess that would be in ram !
2. To get fancy graphics first you need to get the variables into the index.html file I say parables because they don't have to be temperatures for DS18B20 sensors the args can be anything you want to display on your website so first you need to get the macro and callback working, if you don't have the sensors just have the macro as follows, you can then test its working:-

@webiopi.macro
def Temp(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7):
    return ("%s %s %s %s %s %s %s %s %s" % (5, 10, 15, 20, 25, 30, 35, 40)) 
3. The next stage is a table with the values in, I will include something fancy for you but the dials will have to wait until I have some spare time, as I say its fundamental that you get the macro with callback working or nothing else will work.

Toshi  


Shelburne Fire

unread,
Sep 28, 2013, 5:07:12 PM9/28/13
to web...@googlegroups.com
You are correct, Toshi, I had the sensor identifiers mixed up and one in there twice actually.  I have since straightened it out and now have 8 sensors listing the 8 devices and correctly identified.

Attached are the index.html and script.py files.  These have the print (T) syntax in them.  I don't know if this is backward compatible with python 2.7.  They are working well for me.

yes, I have mastered getting the temperatures onto the buttons.  Bring on the next installment!  I really appreciate your efforts on this.

Jim
index.html
script.py

Toshi Bass

unread,
Sep 28, 2013, 6:59:41 PM9/28/13
to web...@googlegroups.com
Jim

Print (T)  etc   will work in Python 2.7 and 3 so I will start using that in future.

So attached is an index.html that essentially is the same as yours with the temp buttons but with addition of a table which includes some cells using the meter tag if you don't want the meter just go through the code and delete all lines that has "meter" in them, 2 points about this code :-

I am no expert in fact I wrote my first line of html / javascript  and indeed Python three months ago, I have no training or a background in software, I don't even know anything about css ( I must check that out) so I do not know if the code is the correct way to do things, or if broke some golden rules of how not to do stuff and there may much easier or better ways to do things, but it works for me and its stable, I would be very happy if someone rewrites parts or all of it as long as they post the results, that way hopefully I and others can learn from that to improve style, skill and understanding, that being said its really difficult to find any examples to extrapolate from, so most of it is trial and error, hopefully this will help you and many others to produce some great results with this fantastic work Trouch did on webiopi.

Also I noted that the meter tag is not supported by all browsers and some interpret it differently I am using chrome and that works fine, I also have IE that doesn't display meter and neither does safari on a iphone so like I said delete the instance of meter if you don't want them.

The next installment could be how I get dials to work if anyone is interested.

Hope it all helps

Toshi Bass

index.html

DavidVT

unread,
Sep 28, 2013, 9:52:47 PM9/28/13
to web...@googlegroups.com
Toshi and all,
I will back out for now and watch this thread develop. Jim is on the same path but I am only at three sensors for now for my log burner.
My ram question was specifically pointed to how the 1wire data point is written to the sd card at the lowest level. I only wonder if that high frequency update might be the cause of my sd card failures. I will set that query aside for now as this thread proceeds.
Keep up the good work!
Jim this is looking great!

Jay Lang

unread,
Sep 29, 2013, 9:52:10 AM9/29/13
to web...@googlegroups.com
Toshi,
thanks got them all going and not bog down.
i also have started learning python(you inspired me thanks) and was able to find one of the missing () on my own:)

here is the code with above changes:
script.py:

# Imports
import webiopi
import time
import sys
sys.path.append("/home/pi/WebIOPi-0.6.0/htdocs")  #<--- or whatever your path is !

# Enable debug output
webiopi.setDebug()

from webiopi.devices.sensor import DS18B20
temp0 = DS18B20(slave="28-000004d112ef")  #< -- your sensor numbers go here, that are designated in the config file 
temp1 = DS18B20(slave="28-00000513b3df")
temp2 = DS18B20(slave="28-000004d13ae6")
temp3 = DS18B20(slave="28-000004d06dc4")
temp4 = DS18B20(slave="28-000004d06df0")
temp5 = DS18B20(slave="28-000004d0beba")
temp6 = DS18B20(slave="28-000004d0f09e")
temp7 = DS18B20(slave="28-000004d06fbc")
temp8 = DS18B20(slave="28-000004d06468")


global T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8
T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8 = 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0
 



def get_DS18B20_Temperature():
    global T, Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8
    if T == 9:
        T = 0
    print(T)
    try:
        if T == 0:
            Temp0 = "%.2f" % (temp0.getCelsius())
        if T == 1:    
            Temp1 = "%.2f" % (temp1.getCelsius())  
        if T == 2: 
            Temp2 = "%.2f" % (temp2.getCelsius())
        if T == 3:  
            Temp3 = "%.2f" % (temp3.getCelsius())
        if T == 4: 
            Temp4 = "%.2f" % (temp4.getCelsius())
        if T == 5: 
            Temp5 = "%.2f" % (temp5.getCelsius())
        if T == 6: 
            Temp6 = "%.2f" % (temp6.getCelsius())
        if T == 7: 
            Temp7 = "%.2f" % (temp7.getCelsius())
        if T == 8: 
            Temp8 = "%.2f" % (temp8.getCelsius())
        T +=1
        print (Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8)
        return Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8
    except (IOError, TypeError):
        print("ERROR getting temp"), T
        #T +=1    # remove this line if you want to retry the same sensor that produced an error again next time.
        pass




@webiopi.macro
def Temp(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8):
    get_DS18B20_Temperature() 
    return ("%s %s %s %s %s %s %s %s %s" % (Temp0, Temp1, Temp2, Temp3, Temp4, Temp5, Temp6, Temp7, Temp8))


index.html: (below existing buttons)
index.html below buttons }}:
function callMacro_Temp(){
 var args = [0, 1, 2, 3, 4, 5, 6, 7, 8]
webiopi().callMacro("Temp", args, macro_Temp_Callback);}
        function macro_Temp_Callback(macro, args, data){
 temp0 = data.split(" ")[0];
 temp1 = data.split(" ")[1];
 temp2 = data.split(" ")[2];
 temp3 = data.split(" ")[3];
 temp4 = data.split(" ")[4];
 temp5 = data.split(" ")[5];
 temp6 = data.split(" ")[6];
 temp7 = data.split(" ")[7];
 temp8 = data.split(" ")[8];

 webiopi().setLabel("macro0", "temp0 " + temp0 +" c");
 webiopi().setLabel("macro1", "temp1 " + temp1 +" c");
 webiopi().setLabel("macro2", "temp2 " + temp2 +" c");
 webiopi().setLabel("macro3", "temp3 " + temp3 +" c");
 webiopi().setLabel("macro4", "temp4 " + temp4 +" c");
 webiopi().setLabel("macro5", "temp5 " + temp5 +" c");
 webiopi().setLabel("macro6", "temp6 " + temp6 +" c");
 webiopi().setLabel("macro7", "temp7 " + temp7 +" c");
 webiopi().setLabel("macro8", "temp8 " + temp8 +" c");}

 setInterval ("callMacro_Temp()", 4000);{

}

index.html below input[type="range"] entry:

Robert More

unread,
Sep 29, 2013, 7:00:15 PM9/29/13
to web...@googlegroups.com
"The next installment could be how I get dials to work if anyone is interested."  ToshiBass

Toshi, that would be great!

Toshi Bass

unread,
Oct 1, 2013, 5:32:08 AM10/1/13
to web...@googlegroups.com
Hi  ,

Gauges, assuming you have the above script.py and index.html all working with the table of values, head over to http://justgage.com/ and click on download, unzip the file and copy the directory named    resources   into your path were your script and index files are like    /home/pi/webiopi/examples/scripts/macros      so the directory  tree will look like this      /home/pi/webiopi/examples/scripts/macros/resources/js          its important to get this correct or the gauges wont work.

If your script.py and index.html are in a different path then you will need to modify the two lines that point to the path in the new index.html attached.

    <script src="resources/js/raphael.2.1.0.min.js"></script>
    <script src="resources/js/justgage.1.0.1.min.js"></script>

When you open you browser you should be seeing the attached Capture1.jpg

If you want you gauges in the table add :

   <tr>
    <td><div id="g1"></div></td>
  </tr>

I recommend you check out customization on  http://justgage.com/  there are many mods you can make to the style and look of your gauges, 

A final note I did check out google gauges and a bunch of others but justgauge is the easiest to understand and get variables into, with nice results, all thanks to the developer  Toorshia  Donate him if you like it.

Hope it helps

Toshi.
index.html
Capture1.JPG

Robert More

unread,
Oct 2, 2013, 9:53:29 PM10/2/13
to web...@googlegroups.com
Toshi, what are you using for the humidity sensor?

Thanks

Incredible work Toshi!

Toshi Bass

unread,
Oct 3, 2013, 8:06:50 AM10/3/13
to web...@googlegroups.com
Hi Robert

I assume from your comment you got the gauges working/? its nice to get some feed back, thanks.

There are a number of Humidity sensors out there, the HIH6130 is nice and it use i2c but there £20 a pop, HYT221 supported by webiopi but stupid price,  I wanted 2 sensors but first I am not a budding weather man so super accuracy is not essential to me and I didn't want to pay more than the price of the Pi to get a couple of humidity readings so I use a couple of cheap DH11 humidity sensors 1 inside and 1 outside cost £2.00 each from the uk  cheaper if you order from china and wait 4 weeks for delivery check, http://www.ebay.co.uk/itm/330880667833?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649    DH22 sensors are pin for pin replacements which offer better accuracy, nether of these sensor types are supported internally in webiopi as they use a propitiatory 1 wire interface so I use small c program written by adifruit that once compiled and copied to the doc path can be called by script.py to retrieve the Humidity and Temp values for each sensor then its a simple case of sending those values to index.html the same way as the Temps, 

I can feel a next installment coming on, how to get DH11 humidity sensors working, if anyone is interested.

Toshi

Robert More

unread,
Oct 3, 2013, 11:03:20 AM10/3/13
to web...@googlegroups.com
Toshi, I have not had a chance to work with the gauges yet, but will this coming weekend.  I have tons of DS18B20 temp sensors but no humidity sensors and was curious what you used.

Next installment please sir.

Thanks
Robert

Toshi Bass

unread,
Oct 3, 2013, 3:00:27 PM10/3/13
to web...@googlegroups.com
OK Robert,

However before I do anymore on this, "installment thing"  I need some feedback from someone that they have the gauges working from the Index.html file supplied.

For information, connecting a BMP085 Barometric sensor (Ebay £3) to the i2c bus and setting it up in config file exactly the same way as you would a DS18B20 temp sensor , calling the sensor say Bar0 will give you the output in Device monitor.

Devices Monitor

Bar0: Temperature: 22.40°C

Bar0: Pressure: 995.22hPa


So it also means that its simple to get these values onto your buttons / table / web page / gauge, or whatever, you just need to add :-

Scipt.py

from webiopi.devices.sensor import BMP085
Bar0 = BMP085(0x77)

Then make 2 additional global variables say bmpt and bmpp then ether replace 2 of the tempX = "%.2f" % (TempX.getCelsius()) with the following or make 2 additional T items to check.

        bmpt = "%.2f" % (Bar0.getCelsius())
        bmpp = "%.1f" % ((Bar0.getHectoPascal())/10) #kPa
 
Under normal circumstance it is only possible to connect 1 BMP085 to your i2c bus because there is no way to change the address of the chip there all the same address you can however have more than one by using a gpio pin for each sensor connected to the interrupt pin and arrange to alternate the gpio state to each sensor whilst getting the values from the other, did all this and got it working great, on my desk the readings were the same (as expected) then I moved one of the sensors outside, guess what, other than a difference of .1 or .2 the readings were still the same, in my naivety I assumed there would be a bigger difference, no, it appears that unless you have some fancy positive or negative pressure house with like an airlock or something, barometric pressure is barometric pressure ! I have now just have 1 BMP085 connected to save 2 gpio pins.

Toshi

Robert More

unread,
Oct 3, 2013, 8:53:04 PM10/3/13
to web...@googlegroups.com
Toshi, the supplied index.html with the gauges works like a charm, (see attachment).  Also, I have a BMP085 on order and have been awaiting it for a couple of weeks now.  The "humidity" sensor in my test is actually another DS18B20.  I plan to order a couple of DH11 sensors later this evening.

Once again, thank you for all of your assistance!

Robert
Message has been deleted

Robert More

unread,
Oct 3, 2013, 8:56:07 PM10/3/13
to web...@googlegroups.com

DavidVT

unread,
Oct 4, 2013, 6:29:11 AM10/4/13
to web...@googlegroups.com
Toshi,
Thank you for showing us 'justgauge' .
I was able to easily implement that on my test page.

While I am still looking at the google gauges simply because of their better control over the zone coloring, your solution is perfect for proof of concept while I focus attention elsewhere!

Thank you for all your efforts here!

Message has been deleted

@legend

unread,
Oct 6, 2013, 10:25:06 PM10/6/13
to web...@googlegroups.com

hi everyone 
i'm new on javascript and i want to display  value  of a sensor TMP75 on web as you do. when i see debug on my screen and it as below but i can't see anything value temp0 on my webbrowser. it only display a button. what's wrong here? anyone can help me 
blow is my debug screen and file index.html, script.py
sorry, my english not well. thanks



index.html
tmp75.py
Message has been deleted
Message has been deleted

Toshi Bass

unread,
Oct 7, 2013, 3:10:25 AM10/7/13
to web...@googlegroups.com
Hi Legend,

Its clear from your debug screen, print statements, that   def get_DS18B20_Temperature():   in the temp75.py script is getting the value of your sensor "30.25" but def Temp(): is not returning this value to the html file, "0" ,  its because the value of Temp0 in the def get_DS18B20_Temperature(): is a local variable but needs to be a global variable so do following:

from webiopi.devices.sensor import TMP75
temp0 = TMP75(slave="0x48")  

global Temp0
Temp0=0

def get_TMP75_Temperature():                         #<-- changed   def get_DS18B20_Temperature(): to   def get_TMP75_Temperature():  just to make it more aesthetically correct.
    global Temp0                                            #<-- add this line
    try:
        Temp0 = "%.2f" % (temp0.getCelsius())
        print (Temp0)
        return Temp0
    except (IOError, TypeError):
        print("ERROR getting temp")
        pass
def Temp():
                                                                       #<-- Shouldn't need it, but if you still have problem try putting in another    global Temp0    line here.
    get_TMP75_Temperature() 
    print Temp0
    return ("%s" %(Temp0))

Hope it helps

Toshi

Toshi Bass

unread,
Oct 10, 2013, 12:55:13 PM10/10/13
to web...@googlegroups.com
Hi all,

DH11 / DH22 / AM2302 humidity and temperature sensor, assuming you have the above script.py and index.html all working with the table of values and gauges, to get values from these sensors you will need a small program written in c from adafruit, webiopi does not have an inbuilt support for these sensors,  I had to download some files from adafruit and compile the program, anyway attached is the compiled program I do not know if this will work as maybe it needs to be compiled locally, so someone needs to go through the process of installing the index.html & python script and checking if this works or if I need to detail what to download and go through the compiling the process. 

The DH11 / DH22 is a 4 wire package however only 3 connections are needed 3v3, gpio, -ve plus a 4.7k resistor see attached diagram Capture2.jpg, or see http://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/overview

One word of warning the DH11 / DH22 sensors can be temperamental, it may take some try's to get readings and for sure its very unlikely you will get continuous readings from them, the python script takes this into account by trying to get the values 3 times on each pass of def get_Humidity(): if it gets the values first time or second time then the loop ends and the values are returned if it doesn't get any new values it uses the old values.
.
To initiate the c program in def get_Humidity(): you need to specify were the file DHT is located the type of sensor and the gpio port used in the form:   

output = subprocess.check_output(["/home/pi/webiopi/examples/scripts/macros/DHT", "11", "8"]); 

or perhaps doc route /home/pi/webiopi/htdocss/DHT

The sensor type "11" or "22" or "AM2302"
And the gpio pin "8" or "X"       X being your connected gpio pin
 

Connect your sensor taking note of the gpio used to amending the output line in script.py.
Unzip and copy the attached c program DHT into your route path, for instance /home/pi/webiopi/examples/scripts/macros.
Copy and paste the attached index.html and script files to the doc route or modify your existing files with the changes (note the additional imports required) also you may need change the permissions to make script.py executable

def Temp(  now includes 2 extra args (obviously you can make a new macro with call back just for this sensor if you wish)

When you open your browser you should be seeing the attached Capture.jpg

There is also code for a gpio label button to play with.

Hope it all works for you, please feed back, let me know if i need to detail were to down load the raw files and how to compile DHT.

Toshi
Capture.JPG
Capture2.JPG
index.html
script.py
DHT.zip

Lutz Bendlin

unread,
Oct 10, 2013, 6:54:15 PM10/10/13
to web...@googlegroups.com
Many thanks, just what I needed for my three AM2302's. How long is your wire to the sensor? Two of mine work fine with about 2 m of cable each, The third sits far away, maybe 20m, and doesn't give me any data. I haven't connected the resistor yet, may try that. It wasn't needed for the other two.


On Thursday, October 10, 2013 12:55:13 PM UTC-4, Toshi Bass wrote:
Hi all,

DH11 / DH22 / AM2302 humidity and temperature sensor, assuming you have the above script.py and index.html all working with the table of values and gauges, to get values from these sensors you will need a small program written in c from adafruit, webiopi does not have an inbuilt support for these sensors,  I had to download some files from adafruit and compile the program, anyway attached is the compiled program I do not know if this will work as maybe it needs to be compiled locally, so someone needs to go through the process of installing the index.html & python script and checking if this works or if I need to detail what to download and go through the compiling the process. 

 
Toshi

Toshi Bass

unread,
Oct 11, 2013, 10:32:11 AM10/11/13
to web...@googlegroups.com
Hi Lutz,

My max run is only 2m however according to the tech spec you can use these sensors at > 20m run, use screened cable and a appropriate sized resistor, you may also connect a 100nF capacitor between vdd and ground to filter the power.

Talking about resistors my advice is to connect resistors to all your sensors, they have 2 functions, 1 to prevent floating, in other words when the pin is read it needs to be a definite state or you will get spurious readings, 2 in certain circumstances like at switch on and when the pin is energized high currents can be generated (in the context higher than 16mA pin current which is more than the sensor and or raspberry pi can handle) so the resistor is there to limit the current pull also.

In other words no resistor means you could blow the top off the sensor or because the gpio pin is connected direct to the broardcom chip in the Pi blow the top of that, best case you could get less reliable readings from the sensor.

Toshi

Tulga Khosbayar

unread,
May 29, 2014, 1:49:47 PM5/29/14
to web...@googlegroups.com
I'm gettin error that says:

AttributeError: 'DS18B20' object has no attribute 'getCelcius'

Toshi Bass

unread,
May 31, 2014, 10:51:11 AM5/31/14
to web...@googlegroups.com
Hi Tulga

This will happen when you have some mismatch between what you have called your sensor in the config file and what you call it in your python script first check that both entry's are identical and make sure the sensor id is correct 

In your python script have you have included the line :  

from webiopi import deviceInstance

If you want more help then you need to post a copy of your config file and python script because its not easy just stabbing in the dark.

Toshi

UWE FISCHER

unread,
Jul 7, 2014, 1:06:25 PM7/7/14
to web...@googlegroups.com
In der Webiopi Version 0.7.0 muss die Syntax so aussehen :

Import von webiopi.devices.sensor.onewiretemp DS18B20






Am Samstag, 31. Mai 2014 16.51.11 UTC +2 schrieb Toshi Bass.:
Hallo Tulga

Dies wird geschehen, wenn Sie einige Missverhältnis zwischen dem, was Sie Ihren Sensor in der Konfigurationsdatei genannt haben und was Sie es in Ihren Python-Skript rufen zunächst prüfen, ob beide Eintrags identisch sind und sicherstellen, dass der Sensor-ID korrekt ist, haben 

In Ihrem Python-Skript haben Sie die Linie aufgenommen haben:  

Import von webiopi deviceInstance

Wenn Sie weitere Hilfe benötigen, dann müssen Sie eine Kopie Ihrer Konfigurationsdatei und Python-Skript zu schreiben, denn es ist nicht einfach nur Messerstecherei in der Dunkelheit.

Toshi

Toshi Bass

unread,
Jul 7, 2014, 3:01:23 PM7/7/14
to web...@googlegroups.com

Hmmm I guess this is just a translation thing but google translates    Import von webiopi.devices.sensor.onewiretemp DS18B20   to:
Import of webiopi.devices.sensor.onewiretemp DS18B20

Just to be clear the syntax should be    from webiopi.devices.sensor.onewiretemp import DS18B20

also

from webiopi import deviceInstance   works fine in webiopi-0.7.0  as it did in webiopi 6 assuming you specify the sensors in the config file

Toshi


Message has been deleted

Dennis L

unread,
Nov 21, 2014, 2:47:55 AM11/21/14
to web...@googlegroups.com
Hi Toshi,

Since 2 weeks ago Im trying to understand to read temperature sensors. I read your topics/posts and tried and tried.
My ds18b20 temp sensors are working, but I have problems to get my DH22 sensor working with Webiopi.

Could it be you made a mistake in the *.py script?

When debugging (I use python3 and Webiopi 070) I get errors in :

except Exception, e:

I have tried to replace the ´,´ in ´as´ and the script is getting no more errors, but the sensor does not work. Should I use ´or´ instead of ´as´ or something else?

also the smbus does not work in python3.
Now the script is working, but the temperature and humidity are showing 0 and not any data. 

Can you help me?



Op donderdag 10 oktober 2013 18:55:13 UTC+2 schreef Toshi Bass:

Dennis L

unread,
Nov 21, 2014, 4:51:46 AM11/21/14
to web...@googlegroups.com
Well, I found out that replacing ',' with "as" in the *.py script is the correct way for python3.
 
I've tested the dht module, and the module works using:
 

mkdir adafruit
cd adafruit
wget https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/archive/master.zip
unzip master.zip

cd Adafruit/Adafruit-Raspberry-Pi-Python-Code-master/Adafruit_DHT_Driver/
sudo ./Adafruit_DHT 22 22

(where the first 22 is the sensor type and the last 22 is my gpio port.)
 
Could there be something wrong with the compiled DHT program?
 
Is there a way to print the temperature and humidity not using the compiled DHT program, but using the ./Adafruit_DHT  ?
 
My (end) goal is to use 2 dht22 sensors and 4 or 5 ds18b20 sensors and make a nice html page to switch 3  relais (with iphone style switches using http://proto.io/freebies/onoff/ ) and to show the temperatures in a nice round colored css style template . Swtches are working great, but the themperature section is not working yet.
 
 

Op vrijdag 21 november 2014 08:47:55 UTC+1 schreef Dennis L:

Dennis L

unread,
Nov 21, 2014, 6:50:09 PM11/21/14
to web...@googlegroups.com
After a couple of hours testing:

Problem was that I used Python3, When I switched over to Python2 the script that Toshi posted works great. Not the best solution, but works as a workaround for me.

Dennis

Toshi Bass

unread,
Nov 22, 2014, 8:04:48 AM11/22/14
to web...@googlegroups.com

Hi Dennis

Sorry I didn't respond earlier was on vacation 

1st you do not need to import smbus for the humidity code

2nd You are right the code was written for python 2.7 and actually I am still using this code, but its quite simple to change the code to work with python 3.2 its just that when python 3.2 came out they made changes to the way it interpreted some functions try this modified code which decodes the output back to a string that can be searched :-

def get_Humidity():
    global D11_Humidity, D11_Temperature
    Last_Humidity = D11_Humidity
    Last_Temperature = D11_Temperature
    try:
        for x in range (3):
            try:
                output = subprocess.check_output(["/home/pi/webiopi/htdocss/DHT", "11", "8"]); # sensor type "11" or "22" , gpio pin "8" or "X" X being your connected gpio pin
                #print (output)
            except Exception, e:
                print (e)
                print("Unable to access D11 c output")
                pass
            valueStr = str(output, encoding='utf8' )
            matches = re.search("Temp =\s+([0-9.]+)", valueStr)
if (matches): temp = float(matches.group(1)) matches = re.search("Hum =\s+([0-9.]+)", valueStr)
humidity = float(matches.group(1)) D11_Temperature = "%.2f" % temp D11_Humidity = "%.0f" % humidity break else: D11_Temperature = Last_Temperature D11_Humidity = Last_Humidity print (D11_Temperature, D11_Humidity) return D11_Temperature, D11_Humidity except Exception, e: print (e) print("Unable to access D11") pass

Hoipe it helps

Toshi

Dennis L

unread,
Nov 24, 2014, 3:15:11 PM11/24/14
to web...@googlegroups.com
Thanks, I'll try this next week. My page and script is running under python 2.7 since last weekend.

I'm now having problems with two ds18b20 sensors who are giving values of 85,0 degrees Celsius sometimes.

sdinet

unread,
Jan 6, 2015, 6:44:00 PM1/6/15
to web...@googlegroups.com
Hey Tosh, what do I put under Sensors (temp0 =) in /etc/webiopi/config and script.py if I am only using a DHT22?  When I run website and attempt to get the DHT22 temp or humidity (D11 Temp/humidity call buttons), I get "global name temp0 is not defined" due to the fact that I am not importing any sensors, since the Webiopi config does not support DHT22.

Toshi Bass

unread,
Jan 7, 2015, 4:23:51 AM1/7/15
to web...@googlegroups.com
Its a little difficult not seeing your actual script but if you are using something like the one I posted you can test it by changing :

from webiopi.devices.sensor import DS18B20
temp0 = DS18B20(slave="28-0000045328a0")     #<--- your sensor numbers as defined in config file
temp1 = DS18B20(slave="28-000004de52e9")
temp2 = DS18B20(slave="28-000004816b68")
temp3 = DS18B20(slave="28-000004f8f104")
temp4 = DS18B20(slave="28-00000515fd8f")
temp5 = DS18B20(slave="28-000005164c50")
temp6 = DS18B20(slave="28-000004f87ee5")
temp7 = 0

to this
 
temp1 = 0
temp2 = 0
temp3 = 0
temp4 = 0
temp5 = 0
temp6 = 0
temp7 = 0

once tested and working you can delete all instance of temp to just have the dh11 part

Toshi

pierantoni...@gmail.com

unread,
Jan 25, 2015, 4:39:56 AM1/25/15
to web...@googlegroups.com
Hello to all!!
Great guide, i followed the entire steps suggested by Toshi, but i don't know why i my raspberry don't work.
Someone can help me please?
I need only 1 temperature because i have one sensor ant then one button, this project is for switch the thermostat of my home and see the temperature inside the house.
The sensor DS18B20 is ok and connected correctly on the gpio, and is readable by raspberry
I attach my garage.html (is the equivalent of standard index.html) and script python, thanks to all.
I attach also the logs:
root@raspberrypi:/home/pi/perry/html# sudo webiopi -c /etc/webiopi/config
2015-01-25 10:37:21 - WebIOPi - INFO - Starting WebIOPi/0.7.0/Python3.2
2015-01-25 10:37:21 - WebIOPi - INFO - GPIO - Native mapped to REST API /GPIO
2015-01-25 10:37:21 - WebIOPi - INFO - Loading configuration from /etc/webiopi/config
2015-01-25 10:37:21 - WebIOPi - INFO - Temperature - DS18B20(slave=28-00042d3d3aff) mapped to REST API /devices/temp0
2015-01-25 10:37:21 - WebIOPi - WARNING - Access unprotected
2015-01-25 10:37:21 - WebIOPi - INFO - HTTP Server binded on http://192.168.1.22:8000/
2015-01-25 10:37:21 - WebIOPi - INFO - CoAP Server binded on coap://224.0.1.123:5683/ (MULTICAST)
2015-01-25 10:37:21 - WebIOPi - INFO - CoAP Server binded on coap://192.168.1.22:5683/
^C2015-01-25 10:37:28 - WebIOPi - INFO - Stopping...
2015-01-25 10:37:28 - WebIOPi - INFO - HTTP Server stopped
2015-01-25 10:37:29 - WebIOPi - INFO - CoAP Server stopped
root@raspberrypi:/home/pi/perry/html# sudo nano /etc/webiopi/config
root@raspberrypi:/home/pi/perry/html# sudo webiopi -c /etc/webiopi/config
2015-01-25 10:37:53 - WebIOPi - INFO - Starting WebIOPi/0.7.0/Python3.2
2015-01-25 10:37:53 - WebIOPi - INFO - GPIO - Native mapped to REST API /GPIO
2015-01-25 10:37:53 - WebIOPi - INFO - Loading configuration from /etc/webiopi/config
2015-01-25 10:37:53 - WebIOPi - INFO - Temperature - DS18B20(slave=28-00042d3d3aff) mapped to REST API /devices/temp0
2015-01-25 10:37:53 - WebIOPi - INFO - Loading myscript from /home/pi/perry/python/script.py
2015-01-25 10:37:54 - WebIOPi - WARNING - Access unprotected
2015-01-25 10:37:54 - WebIOPi - INFO - HTTP Server binded on http://192.168.1.22:8000/
2015-01-25 10:37:54 - WebIOPi - INFO - CoAP Server binded on coap://224.0.1.123:5683/ (MULTICAST)
2015-01-25 10:37:54 - WebIOPi - INFO - CoAP Server binded on coap://192.168.1.22:5683/

and the debug of script.py

root@raspberrypi:/home/pi/perry/python# sudo python script.py
2015-01-25 10:39:35 - WebIOPi - DEBUG - Loading module : w1-therm

Thanks to all!





garage.html
script.py

Toshi Bass

unread,
Jan 25, 2015, 6:53:49 AM1/25/15
to web...@googlegroups.com
Ok try that, indecently I had to put in a dummy value for temp1 in the python script because you have code in your html file for 2 temperatures one on each of the buttons, if you only want to use 1 temp then you need to modify garage.html to remove the second button etc.

Toshi 
garage.html
script.py

pierantoni...@gmail.com

unread,
Jan 25, 2015, 11:39:15 AM1/25/15
to web...@googlegroups.com
Hello Toshi!
Thanks for your fast reply, thanks!
Now is ok, i have disabled the second button "temp1".
Now if i want to view the temperature i must click the yellow button to switch the view, is possible to view in dedicated button? and the temperature did not update automatically , but only if i restart the webiopi.
Can you help me please again, i'm a newbie in python and in javascript ;)
I attach a screenshot
thanks, ciao.
I live in Italy... :)
Pierantonio
Thermostat.png

Toshi Bass

unread,
Jan 25, 2015, 11:53:23 AM1/25/15
to web...@googlegroups.com
Yes my mistake put temp0 = "%.2f" & (temp0.getCelsius()) back in the macro were it was before and you temp will update

Toshi

pierantoni...@gmail.com

unread,
Jan 25, 2015, 12:33:14 PM1/25/15
to web...@googlegroups.com
ok, i added this but now i have this error:


root@raspberrypi:/home/pi/perry/python# sudo python script.py
Traceback (most recent call last):
  File "script.py", line 17, in <module>

    temp0 = "%.2f" & (temp0.getCelsius())
TypeError: unsupported operand type(s) for &: 'str' and 'float'

i attach the script, thanks again
script.py

Toshi Bass

unread,
Jan 26, 2015, 4:56:20 AM1/26/15
to web...@googlegroups.com
Hmmm I was down the pub doing this from memory on my phone, small typo should be:   temp0 = "%.2f" % (temp0.getCelsius())

pierantoni...@gmail.com

unread,
Jan 26, 2015, 8:14:41 AM1/26/15
to web...@googlegroups.com
Hi Toshi, don't worry..
In my script i have already this, i attach my script but the temperature don't update , only if i restart the webiopi.
thanks again ..

Bye
script.py

Pete Dudash

unread,
Jan 26, 2015, 10:56:09 AM1/26/15
to web...@googlegroups.com
i attach my script but the temperature don't update , only if i restart the webiopi.

Yes, that is because the only time the temperature sensors are read is when the script is first called - at startup.  If you want new temperature readings, you must read the sensors again.  There are multiple ways to do this, as Toshi mentioned just a few hours ago in a different thread: Multiple GPIO buttons and Thermostat.  He even gives example code.
Message has been deleted

pierantoni...@gmail.com

unread,
Jan 27, 2015, 3:44:42 AM1/27/15
to web...@googlegroups.com
Hi Pete, thank you very much, i had read the explanation and i tried to add the loop function but don't work, i don't know, most probably because i'm a newbie :(
this is the webiopi log:

root@raspberrypi:/home/pi/perry/python# sudo webiopi -c /etc/webiopi/config

2015-01-27 09:33:09 - WebIOPi - INFO - Starting WebIOPi/0.7.0/Python3.2

2015-01-27 09:33:09 - WebIOPi - INFO - GPIO - Native mapped to REST API /GPIO

2015-01-27 09:33:09 - WebIOPi - INFO - Loading configuration from /etc/webiopi/config

2015-01-27 09:33:09 - WebIOPi - INFO - Temperature - DS18B20(slave=28-00042d3d3aff) mapped to REST API /devices/temp0

2015-01-27 09:33:09 - WebIOPi - INFO - Loading myscript from /home/pi/perry/python/script.py

2015-01-27 09:33:09 - WebIOPi - WARNING - Access unprotected

Exception in thread Thread-1:

Traceback (most recent call last):

  File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner

    self.run()

  File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.0-py3.2-linux-armv6l.egg/webiopi/utils/thread.py", line 23, in run

    self.func()

  File "/home/pi/perry/python/script.py", line 28, in loop

    temp0 = "%.2f" % (temp0.getCelsius())

UnboundLocalError: local variable 'temp0' referenced before assignment


2015-01-27 09:33:09 - WebIOPi - INFO - HTTP Server binded on http://192.168.1.22:8000/

2015-01-27 09:33:09 - WebIOPi - INFO - CoAP Server binded on coap://224.0.1.123:5683/ (MULTICAST)

2015-01-27 09:33:09 - WebIOPi - INFO - CoAP Server binded on coap://192.168.1.22:5683/


and my script attached

thanks to all again!
script.py

Toshi Bass

unread,
Jan 27, 2015, 8:20:56 AM1/27/15
to web...@googlegroups.com
Error is because in your loop temp0 is being treated as a local variable you need to be effecting the global variable temp0 so you need to add the line in red and you should be good to go. 

#Looped by WebIOPi
def loop():
    global temp0   
    temp0 = "%.2f" % (temp0.getCelsius())

    webiopi.sleep(5)

Toshi

pierantoni...@gmail.com

unread,
Jan 27, 2015, 5:40:00 PM1/27/15
to web...@googlegroups.com
Hi Toshi, thanks again, now i added this instruction in the loop but i have this error when i launch webiopi with "sudo webiopi -c /etc/webiopi/config"

temp0 = "%.2f" % (temp0.getCelsius())

AttributeError: 'str' object has no attribute 'getCelsius'


What's the problem ? i don't understand....


thanks


Pierantonio

gillettos

unread,
Jan 28, 2015, 4:33:02 AM1/28/15
to web...@googlegroups.com
 
Hi Guys,
 
Great site and loads of usefull stuf, big thanks to all for supplying in particular Toshi.....
 
One thing I've noticed is that it is all based around the Digital Temperature Sensor DS18B20, which is great as I'm sure it work fine.....
 
My problem is that allot of my sensors are analogue, to which I have a ADC (MCP3008) convertor for it.  I have recently got this working on my pi by using python and the value updates every *.time value - user defined, on a cmd line within putty.
 
My next stage is to build a graphical interface to assign this value to, and reapeat for the other sensors.
 
I have read on here about Just Gauge, which I need to play with later, along with this googe guages......
 
My concern here is assigning the outputs from the ADC (MCP3008), to the guages.  It is fed into the RasPi GPIO through the TXD & RXD pins.
 
Anybody throw any advice on this I'd really appreaciate it as I have been trying to solve this for ages now, and feel I'm so close....... Very close to giving up, which I never do!! haha :0(
 

Toshi Bass

unread,
Jan 28, 2015, 5:56:05 AM1/28/15
to web...@googlegroups.com
Hi Pierantoni, Hi Gillettos

Gellettos 

The MCP3008 works out of the box without serial, I can give you more information but could I ask you to start a brand new post please, because this one is getting crazy.  

Pierantoni

You have a couple of errors in your script

There are two ways to import your DS18B20 sensor into your python script ( you are using both which is not correct, don't mix )

First way you amend the config file and put a line in, like  Temp0 = DS18B20 slave:28-00000xxxxxx   this way you can view the sensor readings in the Devices-Monitor

Then to import into your script.py you would use:

from webiopi import deviceInstance
Temp0 = webiopi.deviceInstance("Temp0")

Second way is to import the DS18B20 sensor directly into your python script, this way you will not see the sensor in the Devices-Monitor

from webiopi.devices.sensor.onewiretemp import DS18B20 
Temp0 = DS18B20(slave="28-00000xxxxxx")


OK you notice I use capital T in Temp0 you need to use a different variable name in the following line or you will get the error your seeing:

 temp0 = "%.2f" % (temp0.getCelsius()) will give an error because you use the same same variable on both sides of the argument

 temp0 = "%.2f" % (Temp0.getCelsius()) # no error

 my_temp0 = "%.2f" % (temp0.getCelsius()) # no error

 DS18B20 = "%.2f" % (temp0.getCelsius()) # no error

So if you decide which method your going to use to import the sensor and remove the surplus lines from your script, and ensure you use a different var name each side of xxxx = "%.2f" % (xxxx.getCelsius()) include   global temp0   or what ever var you use in your loop before the line xxxx = "%.2f" % (xxxx.getCelsius()) then it will work.

Toshi

pierantoni...@gmail.com

unread,
Jan 30, 2015, 2:24:01 AM1/30/15
to web...@googlegroups.com
Hi Toshi, thanks and thanks again for your awesome support.
Now i'd modified the script as you suggested and works perfectly!!
Have a nice day, bye.

Pierantonio

Jamborloi Calampong

unread,
May 10, 2015, 1:30:18 AM5/10/15
to web...@googlegroups.com
Hi Toshi,

I am struggling to find a way to show my mcp3008 with TMP36 output reading in my index.html.
Can you give some examples my tmp336 is connected on channel 1 of the mcp.
I know we can read the as float or as volt or integer.
Can I directly call it in the html file with out doing it in the python script with my formula
temp = ((data * 330)/float(1023))-50
temp = round(temp,places)

Regards,

Jam


On Friday, September 6, 2013 at 5:47:10 AM UTC+8, Toshi Bass wrote:

Hi Aurelien

It doesn't take much to stop a  web page loading, if your using chrome as your web browser try going to the Customize & Control icon - Tools - JavaScript console .. this will help you track-down problems, 

Anyway very simple mistake as follows:-

    }     <-This is incorrect replace with   }); 

               function callMacro_Temp(){
 var args = [0, 1]
webiopi().callMacro("Temp", args, macro_Temp_Callback);}
        function macro_Temp_Callback(macro, args, data){
 temp0 = data.split(" ")[0];
 temp1 = data.split(" ")[1];
 webiopi().setLabel("macro2", "temp0 " + temp0 +" c");
 webiopi().setLabel("macro3", "temp1 " + temp1 +" c");}
 setInterval ("callMacro_Temp()", 6000);{

});    <- This is incorrect replace with   } 
 
     That's it, I ran it and your page is working with these 2 changes above.

Regards

Toshi 

Toshi Bass

unread,
May 11, 2015, 4:29:46 AM5/11/15
to web...@googlegroups.com, jamb...@gmail.com
Sorry I cannot give you any example at the moment as I'am on vacation, however my advice would be first specify / import your mcp xxx in the config file and ensure it is working in the Devices-Monitor
It's possable to get you temp sensor reading direct in the html file but you need to looking up the reading of the mcp pin that the temp sensor is connected to, not expecting to look up the temp sensor directly.
Of coarse the down side of getting the temp sensor reading in your html file is that it will only be avalable when you have the web page open were as if you do it in Python then you get the reading at any time so if you want to switch something say when a set temperature is reached etc then Python is the way to go,

Toshi

Jamborloi Calampong

unread,
May 11, 2015, 8:21:12 AM5/11/15
to web...@googlegroups.com
HI Toshi,

Thank you for the reply.
I got some idea but not so direct as I want it to be. I have my main index.html and python script.

On my python script I put a macro like this:
///////
@webiopi.macro
def get_temp(arg0):
    readc = mcp0.analogRead(0)
    temp = ((readc * 330)/float(1023))-50
    temp = round(temp,2)
    return("%s" % temp)
//////
Then I created another index2.html and calling a script.js which has this:
////////
webiopi().ready(function() {
	var content;
	content = $("#content")
});
		setInterval ("callMacro_get_temp()", 2000);{
		}
		function callMacro_get_force() {
			var arg = [0]
			//call the python macro get_force
                       webiopi().callMacro("get_force", arg, macro_get_force_callback);
                }
		function macro_get_force_callback(macro, arg, data) {
			  content.innerHTML = data.split(" ")[0] +" °C";
		}
////////
My index2.html look like this:
//////
<html>
<head>
<title>RPI 1 Temperature</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body style="background-color: Yellow">
<div id="content" style="text-align: center; color: Black; font-family: verdana"></div>
<p style="text-align: center; font-family: verdana; font-size:50%"><b>RPI_1 Temperature</b></p>
</body>
</html>
////////
Then on my main index.html it is calling my index2.html using an iframe with this:
<iframe width="160" height="45" src="http://*********.ddns.net:8000/index2.html" style="position: absolute; left: -170px; top: 75px"></iframe>
Attached is the screenshot!

But if you have any better direct idea is much better.
I am creating two RPI with each has a camera that was hosted with RPI cam control and webiopi for my temp and PIR sensor that triggers the alarm.
The RPI cam control in port 9700 that is called in my webiopi using iframe as well so that I can have full control of all function in one...
Regards,

Jam
 
  




Toshi

--
You received this message because you are subscribed to the Google Groups "WebIOPi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webiopi+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Screenshot from 2015-05-12 20:12:48.png

Jamborloi Calampong

unread,
May 11, 2015, 8:24:11 AM5/11/15
to web...@googlegroups.com
HI Toshi,

>>>>RESENDING some error in the script.js.....


Thank you for the reply.
I got some idea but not so direct as I want it to be. I have my main index.html and python script.

On my python script I put a macro like this:
///////
@webiopi.macro
def get_temp(arg0):
    readc = mcp0.analogRead(0)
    temp = ((readc * 330)/float(1023))-50
    temp = round(temp,2)
    return("%s" % temp)
//////
Then I created another index2.html and calling a script.js which has this:
////////
webiopi().ready(function() {
	var content;
	content = $("#content")
});
		setInterval ("callMacro_get_temp()", 2000);{
		}
		function callMacro_get_temp() {
			var arg = [0]
			//call the python macro get_force
                       webiopi().callMacro("get_temp", arg, macro_get_temp_callback);
                }
		function macro_get_temp_callback(macro, arg, data) {
			  content.innerHTML = data.split(" ")[0] +" °C";
		}

Toshi

Screenshot from 2015-05-12 20:12:48.png

Gianpic69

unread,
Jun 21, 2016, 6:10:30 PM6/21/16
to WebIOPi

Hello to all
I resume the post because they are several days that I try to bring up the temperatures in the two buttons but I can not figure out where I'm wrong.
From complete novice I was able to build the page attached but to see temperatures just can not, if I connect at http://192.168.1.233:8085/app/devices-monitor I show both sensor work normally.
I would also make sure to send a message gmail detect motion when the PIR sensor (at the time one but I think connect two of them) detects motion only if the alarm was activated by the alarm button.
Can someone come to my rescue, and check the attachment and implement the part relating to the pir's missing?
   Thanks in advance
    GP 
Cattura.JPG
index.html
temperature.py

Toshi Bass

unread,
Jun 22, 2016, 4:47:46 AM6/22/16
to WebIOPi
Move following in red ...
@webiopi.macro
def Temp(arg0, arg1):
    Temp0 = "%.2f" % (temp0.getCelsius())
    Temp1 = "%.2f" % (temp1.getCelsius())
return ("%s %s" % (Temp0, Temp1))

Gianpic69

unread,
Jun 22, 2016, 1:11:57 PM6/22/16
to WebIOPi
Hi Toshi
I modified only temperature.py like you suggested, I rebooted both the Pi and only the webiopi service but the temperatures continue to NOT be seen in the buttons but only in the monitor page.
I can not understand why no functions.
To launch the file, use the command
sudo python3 /home/pi/myproject/html/temperature.py

Regards GP
temperature.py

Toshi Bass

unread,
Jun 22, 2016, 2:30:14 PM6/22/16
to WebIOPi
Hmmm

First add following in red ...

@webiopi.macro
def Temp(arg0, arg1):
    Temp0 = "%.2f" % (temp0.getCelsius())
    Temp1 = "%.2f" % (temp1.getCelsius())
    print (Temp0, Temp1)
    return ("%s %s" % (Temp0, Temp1))

Start webiopi with     sudo webiopi -d -c /etc/webiopi/config   check ssh console window you should see webiopi starting ... a line that says loading your script as you detailed in the config file and you shoud see Temp0 and Temp1 values beeing printed on the console.

That's assuming you did read the Tutorial and have modified the config file to point to your files ?  see  http://webiopi.trouch.com/CONFIGURATION.html

specifically these lines need to be pointing to where you have your index.html and script.py files.

doc-root = /home/pi/webiopi/examples/scripts/macros
welcome-file = index.html
[SCRIPTS]
# name = sourcefile
myscript = /home/pi/webiopi/examples/scripts/macros/script.py


Gianpic69

unread,
Jun 22, 2016, 3:26:13 PM6/22/16
to WebIOPi
Hi Toshi 
i didn't make any modify, I rebooted one more time and finally I did it !!!
Great job, thanks for you patience

The only strange thing is that temperatures appears AFTER I have selected one of the two buttons, after this action the data change depending I warm up the sensors or not.

Now I start to work on sending email with Gmail account or sending push notification with Pushetta service.
do you know this service ?
Other similar services are at payement after some notification, Pushetta , if I understand, are totally free.
i searched on webiopi group if there someone knows this service but I don't find nothing, I'll try again on the web.

the last question, could work different script were inside there are webiopi as gpio and RPi.GPIO as GPIO relate to the same GPIO ?
Cattura.JPG

Suto Andras

unread,
Dec 11, 2016, 1:31:39 PM12/11/16
to WebIOPi
Hello Toshi, Hello Everyone,

I'm still fighting to display the temperature on a web page. For some reason nothing appers when I load the web page. As far as I know I did everything based on your recommandations but it seems I still missed something. Please help me at your first convenience.
Thank you!

Here is the output:


<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
                webiopi().ready(function() {
                var content, button;
                content = $("#content");
                 w().refreshGPIO(true);


                 // create a button which call Temp0
                button = webiopi().createButton("macro2", "Temperature", callMacro_Temp);
                content.append(button); // append button to content div
                webiopi().setClass("macro2", "Temp"); //set color state
        }

        function callMacro_Temp(){
                 var args = [0]

        webiopi().callMacro("Temp", args, macro_Temp_Callback);}
                function macro_Temp_Callback(macro, args, data){
                 Temp0 = data.split(" ")[0];
                 webiopi().setLabel("macro2", "Temp0 " + Temp0 +" c");

                 setInterval ("callMacro_Temp()", 6000);{
        };
</script>

<body>
        <div id="content" align="center"></div>
</body>

2016-12-11 18:12:40 - HTTP - DEBUG - "GET /futesproba.html HTTP/1.1" - 200 OK (Client: ::ffff:31.171.238.104 <Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:50.0) Gecko/20100101 Firefox/50.0>)
2016-12-11 18:12:40 - HTTP - DEBUG - "GET /webiopi.js HTTP/1.1" - 200 OK (Client: ::ffff:31.171.238.104 <Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:50.0) Gecko/20100101 Firefox/50.0>)
Temperature: 23.750000
2016-12-11 18:12:44 - HTTP - DEBUG - "GET /futesproba.html HTTP/1.1" - 200 OK (Client: ::ffff:31.171.238.104 <Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:50.0) Gecko/20100101 Firefox/50.0>)
2016-12-11 18:12:44 - HTTP - DEBUG - "GET /webiopi.js HTTP/1.1" - 200 OK (Client: ::ffff:31.171.238.104 <Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:50.0) Gecko/20100101 Firefox/50.0>)
Temperature: 23.812000
^C2016-12-11 18:12:53 - WebIOPi - INFO - Stopping...
2016-12-11 18:12:53 - WebIOPi - DEBUG - Closing device adc0 - MCP3008(chip=0)
2016-12-11 18:12:53 - WebIOPi - DEBUG - Closing device tmp - DS18B20(slave=28-00000471e805)
2016-12-11 18:12:53 - WebIOPi - DEBUG - Closing device GPIO - GPIO
2016-12-11 18:12:53 - WebIOPi - INFO - HTTP Server stopped
2016-12-11 18:12:54 - WebIOPi - INFO - CoAP Server stopped
pi@raspberrypi:~ $ sudo webiopi -d -c /etc/webiopi/config

autofutes.py
futesproba.html

Toshi Bass

unread,
Dec 12, 2016, 7:43:15 AM12/12/16
to WebIOPi
In your html file mod the RED parts as follows then I think it should work :

 webiopi().ready(function() {
                var content, button;
                content = $("#content");
w().refreshGPIO(true);
               

// create a button which call Temp0
                button = webiopi().createButton("macro2", "Temperature", callMacro_Temp);
       content.append(button); // append button to content div
       webiopi().setClass("macro2", "Temp"); //set color state

  });

  function callMacro_Temp(){
var args = [0]
webiopi().callMacro("Temp", args, macro_Temp_Callback);}

       function macro_Temp_Callback(macro, args, data){
Temp0 = data.split(" ")[0];
webiopi().setLabel("macro2", "Temp0 " + Temp0 +" c");
setInterval ("callMacro_Temp()", 6000);{
}
};

Debugging your javascript code can be achieved by using Ctrl shift i in chrome browser.

Suto Andras

unread,
Dec 12, 2016, 2:47:37 PM12/12/16
to WebIOPi
Hello,


Hoohhhohoo. It works. Thank you. Thank you. Thank's for the debugging proposal also.

I observed one thing. If I try to load the temperature data on my laptop browser and  phone browser at the same time the webiopi crashes and stops with the following error. Did you ebserved something similar? If I'm using on one device only it works without any problem.


2016-12-12 19:30:49 - WebIOPi - INFO - HTTP Server stopped
It is loading more messages.
0 new messages