Sign in to follow this  
Followers 0
Thomasje

Realtime data visualisation

11 posts in this topic

Hi guys,

I started with a project, i would like to automate a little home brewery.

A arduino microntroller reads data from a temp sensor.

Then its displayed via http.

I would like to make a httprequest with a autoit script to see realtime temperature.

This was a succes but the msgbox is flickering beacause of the http requests every second.

is there a way to do every second a request en display this without the flickering?

this is my code

#include <GUIConstantsEx.au3>

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")


Opt("GUIOnEventMode", 1)

Global $ExitID


_Main()

Func _Main()
    Local $YesID, $NoID

    GUICreate("Custom Msgbox", 210, 80)
    While 1 ;start of loop

    connect("http://192.168.1.177/index.php?temp=kamer")
    GUICtrlCreateLabel($oHTTP.Responsetext, 10, 10)
    
    $YesID = GUICtrlCreateButton("Start", 10, 50, 50, 20)
    GUICtrlSetOnEvent($YesID, "OnStart")
    $NoID = GUICtrlCreateButton("Stop", 80, 50, 50, 20)
    GUICtrlSetOnEvent($NoID, "onStop")
    $ExitID = GUICtrlCreateButton("Close", 150, 50, 50, 20)
    GUICtrlSetOnEvent($ExitID, "OnExit")

    GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")

    GUISetState()  ; display the GUI
    
    Sleep(100)
    WEnd

EndFunc   ;==>_Main

;--------------- Functions ---------------
Func OnStart()
    MsgBox(0, "Pomp", "start")
    connect("http://192.168.1.177/index.php?start=pomp")
    
EndFunc

Func OnStop()
    MsgBox(0, "Pomp", "stop")
    connect("http://192.168.1.177/index.php?stop=pomp")

EndFunc 

Func OnExit()
    If @GUI_CtrlId = $ExitID Then
        MsgBox(0, "Sluiten", "Sluiten")
    Else
        MsgBox(0, "Sluiten", "sluiten")
    EndIf

    Exit
EndFunc 

Func connect($var)
    
    $oHTTP.Open("GET", $var, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5")
    $oHTTP.SetRequestHeader("Connection", "Close")
    $oHTTP.Send()
EndFunc

In this code you see it as index.php?temp=kamer

The other function works well.

Kind regards,

Thomas

p.s sorry for my english i'm from Holland.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You should move the creation of the GUI elements outside of the loop and simply use GUICtrlSetData to update the value of the label.<br>You can even slow down the update rate by keeping track of the last temperature displayes and update only when it changes.<br>

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

You should move the creation of the GUI elements outside of the loop and simply use GUICtrlSetData to update the value of the label.<br>You can even slow down the update rate by keeping track of the last temperature displayes and update only when it changes.<br>

Hi,

Thanks for your quick response.

I googled it but i dont know how to this function. Does it update te the label every time?

Share this post


Link to post
Share on other sites

What about looking up this AutoIt function in the AutoIt help bundled with each AutoIt install?

This should answer many questions.

Oh, I see you're kind of new here!

Ok, the help file is now your first best friend, well before Google, when it comes to AutoIt language/functions.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#include <GUIConstantsEx.au3>

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")


Opt("GUIOnEventMode", 1)

Global $ExitID


    
    While 1 ;start of loop

    connect("http://192.168.1.177/index.php?temp=kamer")
    $temp = $oHTTP.Responsetext
    Sleep(2000)
WEnd

_Main()

Func _Main()
    Local $YesID, $NoID

    GUICreate("Custom Msgbox", 210, 80)

    GUICtrlCreateLabel($temp, 10, 10)
    
    $YesID = GUICtrlCreateButton("Start", 10, 50, 50, 20)
    GUICtrlSetOnEvent($YesID, "OnStart")
    $NoID = GUICtrlCreateButton("Stop", 80, 50, 50, 20)
    GUICtrlSetOnEvent($NoID, "onStop")
    $ExitID = GUICtrlCreateButton("Close", 150, 50, 50, 20)
    GUICtrlSetOnEvent($ExitID, "OnExit")

    GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")

GUICtrlSetData(-1, "item1|item2|item3", "item3")
    GUISetState()  ; display the GUI
    


EndFunc   ;==>_Main

;--------------- Functions ---------------
Func OnStart()
    MsgBox(0, "Pomp", "start")
    connect("http://192.168.1.177/index.php?start=pomp")
    
EndFunc

Func OnStop()
    MsgBox(0, "Pomp", "stop")
    connect("http://192.168.1.177/index.php?stop=pomp")

EndFunc 

Func OnExit()
    If @GUI_CtrlId = $ExitID Then
        MsgBox(0, "Sluiten", "Sluiten")
    Else
        MsgBox(0, "Sluiten", "sluiten")
    EndIf

    Exit
EndFunc 

Func connect($var)
    
    $oHTTP.Open("GET", $var, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5")
    $oHTTP.SetRequestHeader("Connection", "Close")
    $oHTTP.Send()
EndFunc

Now I only loop the http request.

But where do i place thet crtlsetdata?

I've read the help but no succes.

Share this post


Link to post
Share on other sites

I obviously can't try that here but it should be close:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

_Main()

Func _Main()
    GUICreate("Custom Msgbox", 210, 80)
    Local $TempLbl = GUICtrlCreateLabel($temp, 10, 10)
    Local $YesID = GUICtrlCreateButton("Start", 10, 50, 50, 20)
    GUICtrlSetOnEvent($YesID, "OnStart")
    Local $NoID = GUICtrlCreateButton("Stop", 80, 50, 50, 20)
    GUICtrlSetOnEvent($NoID, "onStop")
    Local $ExitID = GUICtrlCreateButton("Close", 150, 50, 50, 20)
    GUICtrlSetOnEvent($ExitID, "OnExit")
    GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
;~  GUICtrlSetData(-1, "item1|item2|item3", "item3")
    GUISetState()  ; display the GUI

    While 1 ;start of loop
        connect("http://192.168.1.177/index.php?temp=kamer")
        $temp = $oHTTP.Responsetext
        GUICtrlSetData($TempLbl, $temp)
        Sleep(2000)
    WEnd
EndFunc   ;==>_Main

;--------------- Functions ---------------
Func OnStart()
    MsgBox(0, "Pomp", "start")
    connect("http://192.168.1.177/index.php?start=pomp")
EndFunc

Func OnStop()
    MsgBox(0, "Pomp", "stop")
    connect("http://192.168.1.177/index.php?stop=pomp")
EndFunc

Func OnExit()
    MsgBox(0, "Sluiten", "sluiten")
    Exit
EndFunc

Func connect($var)
    $oHTTP.Open("GET", $var, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5")
    $oHTTP.SetRequestHeader("Connection", "Close")
    $oHTTP.Send()
EndFunc

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I optimised thiss script a little declaring variables and so on.

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Dim $temp
_Main()

Func _Main()
    GUICreate("Custom Msgbox", 210, 80)
    Local $TempLbl = GUICtrlCreateLabel($temp, 10, 10)
    Local $YesID = GUICtrlCreateButton("Start", 10, 50, 50, 20)
    GUICtrlSetOnEvent($YesID, "OnStart")
    Local $NoID = GUICtrlCreateButton("Stop", 80, 50, 50, 20)
    GUICtrlSetOnEvent($NoID, "onStop")
    Local $ExitID = GUICtrlCreateButton("Close", 150, 50, 50, 20)
    GUICtrlSetOnEvent($ExitID, "OnExit")
    GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
;~  GUICtrlSetData(-1, "item1|item2|item3", "item3")
    GUISetState()  ; display the GUI

    While 1 ;start of loop
        connect("http://192.168.1.177/index.php?temp=kamer")
        $temp = $oHTTP.Responsetext
        GUICtrlSetData($TempLbl, $temp)
        Sleep(2000)
    WEnd
EndFunc   ;==>_Main

;--------------- Functions ---------------
Func OnStart()
    MsgBox(0, "Pomp", "start")
    connect("http://192.168.1.177/index.php?start=pomp")
EndFunc

Func OnStop()
    MsgBox(0, "Pomp", "stop")
    connect("http://192.168.1.177/index.php?stop=pomp")
EndFunc

Func OnExit()
    MsgBox(0, "Sluiten", "sluiten")
    Exit
EndFunc

Func connect($var)
    $oHTTP.Open("GET", $var, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5")
    $oHTTP.SetRequestHeader("Connection", "Close")
    $oHTTP.Send()
EndFunc

But what is see now is a small T and after that nothing.

I tried to edit the size of te label but nop success.

Do you know what is wrong?

Share this post


Link to post
Share on other sites

Update:

With a button it works just fine. Who knows what is the cause of this problem?

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Dim $temp
_Main()

Func _Main()
    GUICreate("Custom Msgbox", 210, 80)
    Local $TempLbl = GUICtrlCreateButton($temp, 10, 20, 190, 25)
    Local $YesID = GUICtrlCreateButton("Start", 10, 50, 50, 20)
    GUICtrlSetOnEvent($YesID, "OnStart")
    Local $NoID = GUICtrlCreateButton("Stop", 80, 50, 50, 20)
    GUICtrlSetOnEvent($NoID, "onStop")
    Local $ExitID = GUICtrlCreateButton("Close", 150, 50, 50, 20)
    GUICtrlSetOnEvent($ExitID, "OnExit")
    GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
;~  GUICtrlSetData(-1, "item1|item2|item3", "item3")
    GUISetState()  ; display the GUI

    While 1 ;start of loop
        connect("http://192.168.1.177/index.php?temp=kamer")
        $temp = $oHTTP.Responsetext
        GUICtrlSetData($TempLbl, $temp)
        Sleep(500)
    WEnd
EndFunc   ;==>_Main

;--------------- Functions ---------------
Func OnStart()
    MsgBox(0, "Pomp", "start")
    connect("http://192.168.1.177/index.php?start=pomp")
EndFunc

Func OnStop()
    MsgBox(0, "Pomp", "stop")
    connect("http://192.168.1.177/index.php?stop=pomp")
EndFunc

Func OnExit()
    MsgBox(0, "Sluiten", "sluiten")
    Exit
EndFunc

Func connect($var)
    $oHTTP.Open("GET", $var, False)
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5")
    $oHTTP.SetRequestHeader("Connection", "Close")
    $oHTTP.Send()
EndFunc

Share this post


Link to post
Share on other sites

I looked at that after dinner and found what issue you ran into.

First, you can get rid of the $temp initial value in your label. Why? It's intitially empty and the label is created without width/height specification, so that it defaults to the size needed to display $temp, which is close to nothing as the variable is empty.

When you update it with a non-empty value (your temperature reading, its size isn't enough to display anything useful.

The button you introduced instead has both a width and a heigth, probably large enough to host the string you need it to display.

Is that OK? Did flickering vanish?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0