IntControl(1002, 0, 0, 0, 0);Sets WinBatch icon display state. IntControl (49, 1, 0, 0, 0);Adds system menus to WIL popup windows. IntControl(1008, 0, 0, 0, 0) ;no close command ;If WinMetrics(-2) == 3 Then AddExtender("WWINT64I.DLL") ; 64-bit ;Else AddExtender("WWINT44I.DLL") ; 32-bit ;------------------------------------- ; Standard UrlEncoded POST form data example ;------------------------------------- path=dirscript() ;remove form version 1.0 if fileexist( strcat(path,"setup.ini" ))==1 inideletepvt( "config", "solarindexlist", strcat(path,"setup.ini") ) inideletepvt( "config", "dayindexlist", strcat(path,"setup.ini") ) endif ;add from version 1.1 if fileexist( strcat(path,"setup.ini" ))==0 iniwritepvt( "config", "sunrise", "09:52,09:15,08:03,06:46,05:31,04:37,04:36,05:23,06:25,07:24,08:29,09:08", strcat(path,"setup.ini") ) iniwritepvt( "config", "sunset", "16:53,17:50,18:54,19:59,21:01,21:57,22:11,21:58,20:13,18:53,17:36,16:48", strcat(path,"setup.ini") ) iniwritepvt( "config", "UVindex", "0.60,0.70,0.80,0.90,0.95,1.00,1.00,0.95,0.90,0.80,0.70,0.60", strcat(path,"setup.ini") ) iniwritepvt( "config", "sunchance", "50,60,70,80,80,90,90,90,80,70,60,50", strcat(path,"setup.ini") ) endif nextchange="1970:01:01:00:00:00" #DefineSubRoutine InitDialogConstants() ;DialogprocOptions Constants MSG_INIT=0 ; The one-time initialization MSG_TIMER=1 ; Timer event MSG_BUTTONPUSHED=2 ; Pushbutton or Picturebutton MSG_RADIOPUSHED=3 ; Radiobutton clicked MSG_CHECKBOX=4 ; Checkbox clicked MSG_EDITBOX=5 ; Editbox or Multilinebox MSG_FILESELECT=6 ; Filelistbox MSG_ITEMSELECT=7 ; Itembox MSG_COMBOCHANGE=8 ; Combobox/Droplistbox MSG_CALENDAR=9 ; Calendar date change MSG_SPINNER=10 ; Spinner number change MSG_CLOSEVIA49=11 ; Close clicked (Enabled via DialogProcOptions 1002 MSG_FILEBOXDOUBLECLICK=12 ; Get double-click message on a FileListBox MSG_ITEMBOXDOUBLECLICK=13 ; Get double-click message on an ItemBox MSG_COMEVENT=14 ; COMCONTROL Event notification from DialogObject (NOT DialogProcOptions) MSG_MENUITEM=15 ; MenuItem selected MSG_MENUITEMINIT=16 ; MenuItem initialized MSG_RESIZE=17 ; Dialog resized DPO_DISABLESTATE=1000 ; codes -1=GetSetting 0=EnableDialog 1=DisableDialog DPO_CHANGEBACKGROUND=1001 ; -1=Get Current otherise bitmap or color string DPO_CHANGESYSMENU=1002 ; -1=Get Current 0=none 1=close 2=close/min 3=close/max 4=close/min/max DPO_CHANGETITLE=1003 ; Set/Get Dialog Title - (-1 to get) DPO_GETNAME=1004 ; Returns the name associated with a control's number. DPO_GETNUMBER=1005 ; Returns the number associated with a control's name. DPO_GETCLIENTAREA=1007 ; Returns a space delimited list of the width and height of the client area. ;DialogControlState Constants DCSTATE_SETFOCUS=1 ; Give Control Focus DCSTATE_QUERYSTYLE=2 ; Query control's style DCSTATE_ADDSTYLE=3 ; Add control style DCSTATE_REMOVESTYLE=4 ; Remove control style DCSTATE_GETFOCUS=5 ; Get control that has focus DCSTATE_MOVEMOUSEOVER=6 ; Move the mouse over the control DCSTYLE_DEFAULT=0 ; Set Default Style DCSTYLE_INVISIBLE=1 ; Set Control Invisible DCSTYLE_DISABLED=2 ; Set Control Disabled DCSTYLE_NOUSERDATA=4 ; Note: Setable via DialogControlState function ONLY SPINNER control only DCSTYLE_READONLY=8 ; Sets control to read-only (user cannot type in data) EDITBOX MULTILINEBOX SPINNER DCSTYLE_PASSWORD=16 ; Sets 'password mode' where only *'s are displayed EDITBOX DCSTYLE_DEFAULTBUTTON=32 ; Sets a button as the default button PUSHBUTTON PICTUREBUTTON DCSTYLE_DIGITSONLY=64 ; Set edit box to accept digits only EDITMOX MULTILINEBOX DCSTYLE_FLAT=128 ; Makes a 'flat' hyperlink-looking button PUSHBUTTON PICTUREBUTTON DCSTYLE_NOADJUST=256 ; Turns off auto-height adjustment ITEMBOX FILELISTBOX DCSTYLE_TEXTCENTER=512 ; Center text in control VARYTEXT STATICTEXT DCSTYLE_TEXTRIGHT=1024 ; Flush-Right text in control VARYTEXT STATICTEXT DCSTYLE_NOSELCURLEFT=2048 ; No selection, cursor left EDITBOX MULTILINEBOX DCSTYLE_NOSELCURRIGHT=4096; No selection, cursor right EDITBOX MULTILINEBOX DCSTYLE_SHIELD=8192 ; Display Security Shield icon on button (Vista only) PUSHBUTTON PICTUREBUTTON DCSTYLE_MENUCHECK=32768 ; Adds a check mark to the left of a menu item MENUITEM DCSTYLE_MENURADIO=65536 ; Adds a radio button like dot graphic to the left of a menu item MENUITEM DCSTYLE_MENUSEP=131072 ; Separator bar graphic MENUITEM DCSTYLE_MENUBREAK=262144 ; column break MENUBAR ;DialogControlSet / DialogControlGet Constants DC_CHECKBOX=1 ; CHECKBOX DC_RADIOBUTTON=2 ; RADIOBUTTON DC_EDITBOX=3 ; EDITBOX MULTILINEBOX DC_TITLE=4 ; PICTURE RADIOBUTTON CHECKBOX PICTUREBUTTON VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON MENUITEM DC_ITEMBOXCONTENTS=5 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_ITEMBOXSELECT=6 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_CALENDAR=7 ; CALENDAR DC_SPINNER=8 ; SPINNER DC_MULTITABSTOPS=9 ; MULTILINEBOX DC_ITEMSCROLLPOS=10 ; ITEMBOX FILELISTBOX DC_BACKGROUNDCOLOR=11 ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FILELISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX DC_PICTUREBITMAP=12 ; PICTURE PICTUREBUTTON DC_TEXTCOLOR=13 ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FIELLISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX DC_ITEMBOXADD=14 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_ITEMBOXREMOVE=15 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_RADIOVALUE=16 ; RADIOBUTTON DC_POSITION=17 ; ALL CONTROLS (Except MENUBAR and MENUITEM) DC_MENUNAMES=18 ; ALL CONTROLS DC_HANDLE=19 ; ALL CONTROLS (Except MENUBAR and MENUITEM) ;DialogObject constants DLGOBJECT_ADDEVENT=1 ; Call dialog callback when the specified event occurs DLGOBJECT_STOPEVENT=2 ; Stop calling dialog callback when an event previously requested with DLGOBJECT_GETOBJECT=3 ; Return an object references to the specified control DLGOBJECT_GETPICTURE=4 ; Create and return an object reference to a picture object ;Return code constants RET_DO_CANCEL=0 ; Cancels dialog RET_DO_DEFAULT= -1 ; Continue with default processing for control RET_DO_NOT_EXIT= -2 ; Do not exit the dialog return #EndSubroutine ;============================================================ ;============================================================ ;============================================================ transmittime=TimeYmdHms() ; Returns current date/time in the datetime format. InitDialogConstants() ; Initialize Dialog Constants (need only be done once usually) #DefineSubroutine MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_Name,MyDialog_EventInfo,MyDialog_ChangeInfo) ON_EQUAL = @TRUE ; Initialize variable ON_EQUAL switch MyDialog_Message ; Switch based on Dialog Message type case MSG_INIT ; Standard Initialization message DialogProcOptions(MyDialog_Handle,MSG_TIMER,1000) DialogProcOptions(MyDialog_Handle,MSG_BUTTONPUSHED,@TRUE) DialogProcOptions(MyDialog_Handle,MSG_CHECKBOX,@TRUE) ; DialogProcOptions(MyDialog_Handle,MSG_EDITBOX,@TRUE) DialogProcOptions(MyDialog_Handle,MSG_CALENDAR,@TRUE) X=0 gosub iniload return(RET_DO_DEFAULT) case MSG_TIMER if dialogcontrolget( MyDialog_Handle, "CheckBox_4", DC_CHECKBOX )==1 thistime=TimeYmdHms() ; Returns current date/time in the datetime format. delta_time=TimeDiffSecs( thistime, transmittime ) dialogcontrolset( MyDialog_Handle, "EditBox_countdown", DC_EDITBOX, interval-delta_time ) if delta_time>= interval ; Returns time difference in seconds between the two datetimes. gosub iniload now=TimeYmdHms() ; Returns current date/time in the datetime format. ActivatePower1=inireadpvt("setup", "ActivatePower1", "0", strcat(path,"setup.ini") ) ActivatePower2=inireadpvt("setup", "ActivatePower2", "0", strcat(path,"setup.ini") ) ActivateTemp1=inireadpvt("setup", "ActivateTemp1", "0", strcat(path,"setup.ini") ) gosub calculate url="/input/post.json?node=%node%&json={Power1:%value1%,Power2:%value2%,Temp1:%Value3%}&apikey=%apikey%" tophandle=iBegin(0,"","") datahandle=IUrlOpen(tophandle,strcat(host,url)) iClose(datahandle) iClose(tophandle) transmittime=TimeYmdHms() endif endif return(RET_DO_NOT_EXIT) case MSG_BUTTONPUSHED if MyDialog_Name == "PushButton_Save" ; Save gosub inisave display( 2, "save", "all settings saved" ) return(RET_DO_NOT_EXIT) elseif MyDialog_Name == "PushButton_exit" ; Exit exit return(RET_DO_DEFAULT) elseif MyDialog_Name == "PushButton_1" ; Start gosub iniload if dialogcontrolget( MyDialog_Handle, "EditBox_15", DC_EDITBOX)>0 dialogcontrolset( MyDialog_Handle, "CheckBox_4", DC_CHECKBOX,0 ) ActivatePower1=inireadpvt("setup", "ActivatePower1", "0", strcat(path,"setup.ini") ) ActivatePower2=inireadpvt("setup", "ActivatePower2", "0", strcat(path,"setup.ini") ) ActivateTemp1=inireadpvt("setup", "ActivateTemp1", "0", strcat(path,"setup.ini") ) gosub iniload ;tophandle=iBegin(0,"","") for X=1 to NoOfRecords tophandle=iBegin(0,"","") dialogcontrolset( MyDialog_Handle, "EditBox_12", DC_EDITBOX,NoOfRecords-x ) now=StartunixTime1 gosub calculate url="/input/post.json?node=%node%&json={Power1:%value1%,Power2:%value2%,Temp1:%Value3%}&apikey=%apikey%&time=%unixTime1%" ;connecthandle=iHostConnect(tophandle, host, @HTTP, "", "") ;datahandle=iHttpInit(connecthandle,"POST","","", 7) ;iHttpOpen(datahandle, url , 0, 0) datahandle=IUrlOpen(tophandle,strcat(host,url)) unixTime1=unixTime1 + interval AddTime = "0000:00:00:00:00:%interval%" StartunixTime1=TimeAdd( StartunixTime1, AddTime ) ; Adds two YmdHms variables ;iClose(datahandle) ;iClose(tophandle) iClose(datahandle) ;iClose(connecthandle) iClose(tophandle) delay(0.02) ;Yield ; Provides a fixed time for other windows to do processing. ;Yield ; Provides a fixed time for other windows to do processing. ;Yield ; Provides a fixed time for other windows to do processing. next ;iClose(datahandle) ;iClose(tophandle) dialogcontrolset( MyDialog_Handle, "CheckBox_4", DC_CHECKBOX,1 ) endif return(RET_DO_NOT_EXIT) endif ; MyDialog_Name return(RET_DO_DEFAULT) case MSG_CHECKBOX if MyDialog_Name == "CheckBox_1" ; ActivatePower1 On/Off return(RET_DO_DEFAULT) elseif MyDialog_Name == "CheckBox_2" ; ActivatePower2 On/Off return(RET_DO_DEFAULT) elseif MyDialog_Name == "CheckBox_3" ; cbVariable2 On/Off return(RET_DO_DEFAULT) elseif MyDialog_Name == "CheckBox_4" ; Transmit Transmit On/Off return(RET_DO_NOT_EXIT) endif ; MyDialog_Name return(RET_DO_DEFAULT) ; case MSG_EDITBOX ; if MyDialog_Name == "EditBox_1" ; http_server_IP http://emoncms.org ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_2" ; APIKEY xxxxxxxxxx ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_3" ; node_number No. or name ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_5" ; NormPower1 1000 ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_6" ; RandomPower1 1 ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_4" ; NormPower2 1000 ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_7" ; RandomPower2 1 ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_8" ; RandomTwmp1 20 ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_9" ; RandomTemp1 1 ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_10" ; DiffTemp1 2 ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "EditBox_11" ; FrequencyTemp1 1 ; return(RET_DO_DEFAULT) ; endif ; MyDialog_Name ; return(RET_DO_DEFAULT) case MSG_CALENDAR if MyDialog_Name == "Calendar_1" ; CalendarTime1 StartunixTime1=dialogcontrolget( MyDialog_Handle, "Calendar_1", DC_CALENDAR ) unixTime1=(TimeDiffSecs( StartunixTime1, "1970:01:01:00:00:00" ))-7200 ; Returns time difference in seconds between the two datetimes. dialogcontrolset( MyDialog_Handle, "EditBox_13", DC_EDITBOX, unixTime1 ) if dialogcontrolget( MyDialog_Handle, "EditBox_13", DC_EDITBOX)<>"" && dialogcontrolget( MyDialog_Handle, "EditBox_8", DC_EDITBOX )<>"" NoOfRecords=( unixTime2-unixTime1 )/ interval dialogcontrolset( MyDialog_Handle, "EditBox_15", DC_EDITBOX, NoOfRecords ) endif return(RET_DO_DEFAULT) elseif MyDialog_Name == "Calendar_2" ; CalendarTime2 unixTime2=dialogcontrolget( MyDialog_Handle, "Calendar_2", DC_CALENDAR ) unixTime2=(TimeDiffSecs( unixTime2, "1970:01:01:00:00:00" ))-7200 ; Returns time difference in seconds between the two datetimes. dialogcontrolset( MyDialog_Handle, "EditBox_8", DC_EDITBOX, unixTime2 ) if dialogcontrolget( MyDialog_Handle, "EditBox_13", DC_EDITBOX)<>"" && dialogcontrolget( MyDialog_Handle, "EditBox_8", DC_EDITBOX )<>"" NoOfRecords=( unixTime2-unixTime1 )/ interval dialogcontrolset( MyDialog_Handle, "EditBox_15", DC_EDITBOX, NoOfRecords ) endif return(RET_DO_DEFAULT) endif ; MyDialog_Name return(RET_DO_DEFAULT) endswitch ; MyDialog_Message return(RET_DO_DEFAULT) :iniload ;solarindexlist=inireadpvt( "config", "solarindexlist", "", strcat(path,"setup.ini") ) ;dayindexlist=inireadpvt( "config", "dayindexlist", "", strcat(path,"setup.ini") ) sunsetlist=inireadpvt( "config", "sunset", "00:00", strcat(path,"setup.ini") ) sunriselist=inireadpvt( "config", "sunrise", "00:00", strcat(path,"setup.ini") ) UVindexlist=inireadpvt( "config", "UVindex", "1", strcat(path,"setup.ini") ) sunchancelist=inireadpvt( "config", "sunchance", "1", strcat(path,"setup.ini") ) apikey=inireadpvt("config", "apikey", "set api key", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_2", DC_EDITBOX, apikey ) host=inireadpvt("config", "host", "http://localhost:8080", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_1", DC_EDITBOX, host ) node=inireadpvt("config", "node", "2", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_3", DC_EDITBOX, node ) NormPower1=inireadpvt("setup", "NormPower1", "1000", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_5", DC_EDITBOX, NormPower1 ) RandomPower1=inireadpvt("setup", "RandomPower1", "25", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_6", DC_EDITBOX, RandomPower1 ) ActivatePower1=inireadpvt("setup", "ActivatePower1", "0", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "CheckBox_1", DC_CHECKBOX, ActivatePower1 ) NormPower2=inireadpvt("setup", "NormPower2", "1000", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_4", DC_EDITBOX, NormPower2) RandomPower2=inireadpvt("setup", "RandomPower2", "25", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_7", DC_EDITBOX, RandomPower2 ) ActivatePower2=inireadpvt("setup", "ActivatePower2", "0", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "CheckBox_2", DC_CHECKBOX, ActivatePower2 ) NormTemp1=inireadpvt("setup", "NormTemp1", "20", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_NormTemp1", DC_EDITBOX, NormTemp1) Randomtemp1=inireadpvt("setup", "Randomtemp1", "1", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_9", DC_EDITBOX, Randomtemp1) DiffTemp1=inireadpvt("setup", "DiffTemp1", "2", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_10", DC_EDITBOX, DiffTemp1) FrequencyTemp1=inireadpvt("setup", "FrequencyTemp1", "1", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_11", DC_EDITBOX, FrequencyTemp1) ActivateTemp1=inireadpvt("setup", "ActivateTemp1", "0", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "CheckBox_3", DC_CHECKBOX, ActivateTemp1 ) interval=inireadpvt("config", "interval", "20", strcat(path,"setup.ini") ) dialogcontrolset( MyDialog_Handle, "EditBox_interval", DC_EDITBOX, interval) return :inisave apikey=dialogcontrolget( MyDialog_Handle, "EditBox_2", DC_EDITBOX ) iniwritepvt("config", "apikey", apikey, strcat(path,"setup.ini") ) host=dialogcontrolget( MyDialog_Handle, "EditBox_1", DC_EDITBOX ) iniwritepvt("config", "host", host, strcat(path,"setup.ini") ) node=dialogcontrolget( MyDialog_Handle, "EditBox_3", DC_EDITBOX ) iniwritepvt("config", "node", node, strcat(path,"setup.ini") ) NormPower1=dialogcontrolget( MyDialog_Handle, "EditBox_5", DC_EDITBOX ) iniwritepvt("setup", "NormPower1", NormPower1, strcat(path,"setup.ini") ) RandomPower1=dialogcontrolget( MyDialog_Handle, "EditBox_6", DC_EDITBOX ) iniwritepvt("setup", "RandomPower1", RandomPower1, strcat(path,"setup.ini") ) ActivatePower1=dialogcontrolget( MyDialog_Handle, "CheckBox_1", DC_CHECKBOX ) iniwritepvt("setup", "ActivatePower1", ActivatePower1, strcat(path,"setup.ini") ) NormPower2=dialogcontrolget( MyDialog_Handle, "EditBox_4", DC_EDITBOX ) iniwritepvt("setup", "NormPower2", NormPower2, strcat(path,"setup.ini") ) RandomPower2=dialogcontrolget( MyDialog_Handle, "EditBox_7", DC_EDITBOX ) iniwritepvt("setup", "RandomPower2", RandomPower2, strcat(path,"setup.ini") ) ActivatePower2=dialogcontrolget( MyDialog_Handle, "CheckBox_2", DC_CHECKBOX ) iniwritepvt("setup", "ActivatePower2", ActivatePower2, strcat(path,"setup.ini") ) NormTemp1=dialogcontrolget( MyDialog_Handle, "EditBox_NormTemp1", DC_EDITBOX) iniwritepvt("setup", "NormTemp1", NormTemp1, strcat(path,"setup.ini") ) Randomtemp1=dialogcontrolget( MyDialog_Handle, "EditBox_9", DC_EDITBOX ) iniwritepvt("setup", "Randomtemp1", Randomtemp1, strcat(path,"setup.ini") ) DiffTemp1=dialogcontrolget( MyDialog_Handle, "EditBox_10", DC_EDITBOX) iniwritepvt("setup", "DiffTemp1", DiffTemp1, strcat(path,"setup.ini") ) FrequencyTemp1=dialogcontrolget( MyDialog_Handle, "EditBox_11", DC_EDITBOX) iniwritepvt("setup", "FrequencyTemp1", FrequencyTemp1, strcat(path,"setup.ini") ) ActivateTemp1=dialogcontrolget( MyDialog_Handle, "CheckBox_3", DC_CHECKBOX ) iniwritepvt("setup", "ActivateTemp1", ActivateTemp1, strcat(path,"setup.ini") ) interval=dialogcontrolget( MyDialog_Handle, "EditBox_interval", DC_EDITBOX) iniwritepvt("config", "interval", interval, strcat(path,"setup.ini") ) return :calculate ;now="2017:06:29:22:00:00" year=strsub( now, 1, 4 ) nextyear=year month=strsub( now, 6, 2 ) day=strsub( now, 9, 2 ) hour=strsub( now, 12, 2 ) minut=strsub( now, 15, 2) Nextmonth=month+1 if Nextmonth==13 nextmonth=1 nextyear=year+1 endif uvindex=itemextract( month, uvindexlist, "," ) sunchance=itemextract( month, sunchancelist, "," ) sunriseThisMonth=itemextract( month, sunriselist, "," ) sunriseNextMonth=itemextract( nextmonth, sunriselist, "," ) sekundstoaddsunrise=((TimeDiffSecs("%year%:%Month%:01:%sunriseNextMonth%:00" ,"%year%:%Month%:01:%sunriseThisMonth%:00" ))/30)* day if sekundstoaddsunrise<0 sekundstoaddsunrise=sekundstoaddsunrise *-1 sunrisetoday=TimeSubtract( "%year%:%Month%:%day%:%sunriseThisMonth%:00", "0000:00:00:00:00:%sekundstoaddsunrise%" ) else sunrisetoday=timeadd( "%year%:%Month%:%day%:%sunriseThisMonth%:00", "0000:00:00:00:00:%sekundstoaddsunrise%" ) endif sunsetThisMonth=itemextract( month, sunsetlist, "," ) sunsetNextMonth=itemextract( nextmonth, sunsetlist, "," ) sekundstoaddSunset=((TimeDiffSecs("%year%:%Month%:01:%sunsetNextMonth%:00" ,"%year%:%Month%:01:%sunsetThisMonth%:00" ))/30)* day if sekundstoaddSunset<0 sekundstoaddSunset=sekundstoaddSunset *-1 sunsettoday=TimeSubtract( "%year%:%Month%:%day%:%sunsetThisMonth%:00", "0000:00:00:00:00:%sekundstoaddSunset%" ) else sunsettoday=timeadd( "%year%:%Month%:%day%:%sunsetThisMonth%:00", "0000:00:00:00:00:%sekundstoaddSunset%" ) endif a1=TimeDiffSecs( sunsettoday,sunrisetoday) a2=a1/180.00 a3= TimeDiffSecs(now,sunrisetoday) angle=( a3 /a2) if angle>180 then angle=180 if angle<0 then angle=0 powerindex=sin(angle*@DEG2RAD) if powerindex<0 then powerindex=0 if TimeDiffSecs( now, sunsettoday )>0 then powerindex=0 ;info=TimeDiffSecs( now, nextchange ) if TimeDiffSecs( now, nextchange )> 0 sunrandom=random(100) ;if sunrandom < sunchance if sunrandom < 50 ;if sunrandom mod 2 == 0 ;Even sunpower=1 else sunpower=0 for y=1 to 4 sunpower=random(25) + sunpower next Sunpower=Sunpower /100.00 ;sunpower=(random(25)+random(25)+random(25)+random(25))/100 ;sunpower=0.5 endif ;display(1,"",sunpower) ;randomtime=random(3) + random(3) +random(3) randomtime=1 for z = 1 to 3 randomtime = randomtime + random(3) next nextchange=TimeAdd( now, "0000:00:00:00:%randomtime%:00" ) ; Adds two YmdHms variables endif ;value1=(NormPower1*powerindex*uvindex*sunpower)+ random(RandomPower1) ;if inireadpvt("setup", "ActivatePower1", "0", strcat(path,"setup.ini") )==1 if ActivatePower1==1 value1=(NormPower1*powerindex*uvindex*sunpower) - random(RandomPower1) if value1<0 then value1=0 else value1=0 endif ;if inireadpvt("setup", "ActivatePower2", "0", strcat(path,"setup.ini") )==1 if ActivatePower2==1 value2=(NormPower2*powerindex*uvindex*sunpower)+ random(RandomPower2)) else value2=0 endif ;if inireadpvt("setup", "ActivateTemp1", "0", strcat(path,"setup.ini") )==1 if ActivateTemp1==1 value3=DiffTemp1*(Sin(minut*6*FrequencyTemp1 * @DEG2RAD))+NormTemp1+(random(Randomtemp1) / 10.00) else value3=300 endif value2=powerindex return ;from calculate #EndSubroutine ; End of Dialog Callback MyDialogCallbackProc ;============================================================ ;============================================================ ;============================================================ MyDialogFormat=`WWWDLGED,6.2` MyDialogCaption=`EmonTx3 simulator By Henrik v.1.1` MyDialogX=053 MyDialogY=103 MyDialogWidth=460 MyDialogHeight=141 MyDialogNumControls=046 MyDialogProcedure=`MyDialogCallbackProc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`012,092,032,011,PUSHBUTTON,"PushButton_Save",DEFAULT,"Save",1,10,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`012,105,032,011,PUSHBUTTON,"PushButton_exit",DEFAULT,"Exit",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`009,007,118,054,GROUPBOX,"GroupBox_1",DEFAULT,"EmonCMS server",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog004=`015,022,019,006,STATICTEXT,"StaticText_1",DEFAULT,"Host IP",DEFAULT,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog005=`036,020,086,011,EDITBOX,"EditBox_1",http_server_IP,"http://emoncms.org",DEFAULT,50,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog006=`015,033,019,006,STATICTEXT,"StaticText_2",DEFAULT,"APIKEY",DEFAULT,60,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog007=`036,031,086,011,EDITBOX,"EditBox_2",APIKEY,"xxxxxxxxxx",DEFAULT,70,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog008=`015,046,019,006,STATICTEXT,"StaticText_4",DEFAULT,"Node",DEFAULT,100,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog009=`036,046,086,009,EDITBOX,"EditBox_3",node_number,"No. or name",DEFAULT,110,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog010=`135,007,064,054,GROUPBOX,"GroupBox_2",DEFAULT,"Power 1",DEFAULT,140,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog011=`140,022,032,006,STATICTEXT,"StaticText_7",DEFAULT,"Norm power",DEFAULT,150,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog012=`175,020,022,011,EDITBOX,"EditBox_5",NormPower1,"1000",DEFAULT,160,64,DEFAULT,DEFAULT,DEFAULT` MyDialog013=`140,034,033,008,STATICTEXT,"StaticText_8",DEFAULT,"Random filter",DEFAULT,170,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog014=`175,033,016,011,EDITBOX,"EditBox_6",RandomPower1,"1",DEFAULT,180,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog015=`140,046,041,006,CHECKBOX,"CheckBox_1",ActivatePower1,"On/Off",1,190,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog016=`207,007,064,054,GROUPBOX,"GroupBox_4",DEFAULT,"Power 2",DEFAULT,140,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog017=`212,022,032,006,STATICTEXT,"StaticText_6",DEFAULT,"Norm power",DEFAULT,150,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog018=`212,034,033,008,STATICTEXT,"StaticText_3",DEFAULT,"Random filter",DEFAULT,170,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog019=`247,020,022,011,EDITBOX,"EditBox_4",NormPower2,"1000",DEFAULT,160,64,DEFAULT,DEFAULT,DEFAULT` MyDialog020=`247,033,016,011,EDITBOX,"EditBox_7",RandomPower2,"1",DEFAULT,180,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog021=`214,046,038,006,CHECKBOX,"CheckBox_2",ActivatePower2,"On/Off",1,190,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog022=`135,063,064,072,GROUPBOX,"GroupBox_7",DEFAULT,"Temp 1 (room temp)",DEFAULT,240,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog023=`142,074,030,008,STATICTEXT,"StaticText_10",DEFAULT,"Norm. temp",DEFAULT,250,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog024=`175,073,016,011,EDITBOX,"EditBox_NormTemp1",NormTemp1,"20",DEFAULT,260,64,DEFAULT,DEFAULT,DEFAULT` MyDialog025=`140,087,033,008,STATICTEXT,"StaticText_5",DEFAULT,"Random filter",DEFAULT,170,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog026=`175,086,016,009,EDITBOX,"EditBox_9",RandomTemp1,"1",DEFAULT,180,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog027=`143,100,027,008,STATICTEXT,"StaticText_12",DEFAULT,"Diff.",DEFAULT,290,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog028=`175,098,016,011,EDITBOX,"EditBox_10",DiffTemp1,"2",DEFAULT,300,64,DEFAULT,DEFAULT,DEFAULT` MyDialog029=`142,124,038,008,CHECKBOX,"CheckBox_3",cbVariable2,"On/Off",1,310,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog030=`140,113,027,006,STATICTEXT,"StaticText_9",DEFAULT,"Frequency",DEFAULT,280,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog031=`175,111,016,011,EDITBOX,"EditBox_11",FrequencyTemp1,"1",DEFAULT,270,64,DEFAULT,DEFAULT,DEFAULT` MyDialog032=`012,063,051,008,CHECKBOX,"CheckBox_4",Transmit,"Transmit On/Off",1,320,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog033=`014,078,022,006,STATICTEXT,"StaticText_14",DEFAULT,"interval",DEFAULT,330,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog034=`036,076,017,011,EDITBOX,"EditBox_interval",interval,DEFAULT,DEFAULT,340,64,DEFAULT,DEFAULT,DEFAULT` MyDialog035=`055,076,016,011,EDITBOX,"EditBox_countdown",countdown,DEFAULT,DEFAULT,350,8,DEFAULT,DEFAULT,DEFAULT` MyDialog036=`279,012,080,078,CALENDAR,"Calendar_1",CalendarTime1,DEFAULT,DEFAULT,360,DEFAULT,DEFAULT` MyDialog037=`369,012,080,078,CALENDAR,"Calendar_2",CalendarTime2,DEFAULT,DEFAULT,370,DEFAULT,DEFAULT` MyDialog038=`281,094,022,006,STATICTEXT,"StaticText_16",DEFAULT,"Unix Start",DEFAULT,380,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog039=`372,094,024,006,STATICTEXT,"StaticText_11",DEFAULT,"Unix Stop",DEFAULT,380,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog040=`308,092,051,011,EDITBOX,"EditBox_13",UnixStart,DEFAULT,DEFAULT,400,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog041=`398,092,049,011,EDITBOX,"EditBox_8",UnixStop,DEFAULT,DEFAULT,410,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog042=`279,106,051,008,STATICTEXT,"StaticText_18",DEFAULT,"Number of records",DEFAULT,420,1024,DEFAULT,DEFAULT,DEFAULT` MyDialog043=`332,105,027,011,EDITBOX,"EditBox_15",UnixRecords,DEFAULT,DEFAULT,430,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog044=`377,106,043,008,STATICTEXT,"StaticText_13",DEFAULT,"Records to go",DEFAULT,440,1024,DEFAULT,DEFAULT,DEFAULT` MyDialog045=`422,105,025,011,EDITBOX,"EditBox_12",recordsToGo,DEFAULT,DEFAULT,450,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog046=`353,121,035,011,PUSHBUTTON,"PushButton_1",DEFAULT,"Start",2,460,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog")