TheUnexplained

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
martindtm
Posts: 3
Joined: Wednesday 3rd January 2024 4:07pm

TheUnexplained

Post by martindtm »

I have a realy strange problem. I will try to describe it here:
My gambas program is creating an html file that is copied the the /var/www/html folder(THE WEBSITE).
I'm using this to monitor room temperature in a workshop.

While logged into my laptop remotely or local:

The html file is created perfectly and generates a link button which displays the historical temperatures from a file on THE WEBSITE.
This link button includes the ipaddress of the laptop with the name of the file with the history recrods in it.
it works perfectly. Also I have other computers (hardwired ethernet, Not wireless like the laptop pc) where this problem does not exist.

<!DOCTYPE html>
<!-- -->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8 "/>
<title></title>
<meta name= "generator" content="LibreOffice 7.5.5.2 (Linux)"/>
<meta name= "created" content="2023-08-05T08:42:00.296569589"/>
<meta name= "changed" content="2023-08-05T08:53:08.939254815"/>
<style type= "text/css">
@page { size: 8.0in 11in; margin: 0.79in }
p { line-height: 100%; margin-bottom: 0.1in; background: transparent; background: transparent }
h1 { margin-bottom: 0.08in; background: transparent; page-break-after: avoid }
h1.western { font-family: "Liberation Sans", sans-serif; font-size: 18px; font-weight: bold }
h1.cjk { font-family: "Noto Sans CJK SC"; font-size: 24px; font-weight: bold }
h1.ctl { font-family: "Lohit Devanagari"; font-size: 24px; font-weight: bold }
a:link { color: #000080; text-decoration: underline }
a:visited { color: #800000; text-decoration: underline }
</style>
<meta http-equiv="refresh" content="30" >
</head>
<body lang= "en-US" link="#000080"vlink= "#800000" dir="ltr"><p style="line-height: 100%; margin-bottom: 0in">
<br/>

</p>
<p style= "line-height: 100%; margin-bottom: 0in"><br/>

</p>
<h1 class="western" align="center"><font face="Liberation Serif, serif" >Workshop___________________ 48°</font></h1>
<h1 class="western" align="center"><font face="Liberation Serif, serif" >Wednesday 01/03/2024 11:23:58 am</font></h1>
<p align= "center" style= "line-height: 100%; margin-bottom: 0in"><a href=
HERE IT DOES INSERT THE IPADDRESS.
|
"http://192.168.1.34/ShowTempMonStat.html"><font size= "5" style= "font-size: 24px
"> Show history readings</font></a></p >

</body>
</html>

Running the applicationn as root when laptop reboots:
With this set up I created a cron job to reboot the laptop at the beginning of each day and start the gambas executible to do all this.
However, when the html page is created it will not imbed the ip address into it. It just leaves a blank spot and subsequently the link button fails.

<!DOCTYPE html>
<!-- -->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8 "/>
<title></title>
<meta name= "generator" content="LibreOffice 7.5.5.2 (Linux)"/>
<meta name= "created" content="2023-08-05T08:42:00.296569589"/>
<meta name= "changed" content="2023-08-05T08:53:08.939254815"/>
<style type= "text/css">
@page { size: 8.0in 11in; margin: 0.79in }
p { line-height: 100%; margin-bottom: 0.1in; background: transparent; background: transparent }
h1 { margin-bottom: 0.08in; background: transparent; page-break-after: avoid }
h1.western { font-family: "Liberation Sans", sans-serif; font-size: 18px; font-weight: bold }
h1.cjk { font-family: "Noto Sans CJK SC"; font-size: 24px; font-weight: bold }
h1.ctl { font-family: "Lohit Devanagari"; font-size: 24px; font-weight: bold }
a:link { color: #000080; text-decoration: underline }
a:visited { color: #800000; text-decoration: underline }
</style>
<meta http-equiv="refresh" content="30" >
</head>
<body lang= "en-US" link="#000080"vlink= "#800000" dir="ltr"><p style="line-height: 100%; margin-bottom: 0in">
<br/>

</p>
<p style= "line-height: 100%; margin-bottom: 0in"><br/>

</p>
<h1 class="western" align="center"><font face="Liberation Serif, serif" >Workshop___________________ 48°</font></h1>
<h1 class="western" align="center"><font face="Liberation Serif, serif" >Wednesday 01/03/2024 11:23:58 am</font></h1>
<p align= "center" style= "line-height: 100%; margin-bottom: 0in"><a href=
HERE IT DOES NOT INSERT THE IPADDRESS.
|
"http:///ShowTempMonStat.html"><font size= "5" style= "font-size: 24px
"> Show history readings</font></a></p >

</body>
</html>

I hope someone might have a clue for what is happening.
The only dumb questions are the ones that never get asked.
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: TheUnexplained

Post by BruceSteers »

How are you getting and inserting the ip address?
what method exactly?
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: TheUnexplained

Post by cogier »

It's possible that when your program starts on boot the system is not quite ready yet. I suggest you allow some time for it to settle down before you start your program. I use Linux Mint which allows for a period of time after boot before your program starts. You can see below that even some of the system programs are delayed.

Image
martindtm
Posts: 3
Joined: Wednesday 3rd January 2024 4:07pm

Re: TheUnexplained

Post by martindtm »

BruceSteers wrote: Thursday 4th January 2024 2:58am How are you getting and inserting the ip address?
what method exactly?
Hey; thanks for the reply.
I get the ip address by using Shell( hostname -I ) to myip:

Instead of using a return I just create a global variable named myip.
When this Sub is called it just updates it.
I put the Loop in it to make shure, if the system was not settled down after startup, to set the ip.


Public Sub Get_myip()

If Dbug = "yes" Then Print "get_myip() has been reached"


Dim colspace As Integer

loopit:
Shell "hostname -I" To myip

If myip = "" Then Goto loopit

colspace = InStr(myip, " ")

myip = Left$(myip, colspace - 1)

Print "this is my id address: " & myip
End

The only dumb questions are the ones that never get asked.
martindtm
Posts: 3
Joined: Wednesday 3rd January 2024 4:07pm

Re: TheUnexplained

Post by martindtm »

cogier wrote: Friday 5th January 2024 1:33pm It's possible that when your program starts on boot the system is not quite ready yet. I suggest you allow some time for it to settle down before you start your program. I use Linux Mint which allows for a period of time after boot before your program starts. You can see below that even some of the system programs are delayed.

Image
Thanks for the suggestion.
I will look into that.

Currently I start the program with a cron job setup.
The only dumb questions are the ones that never get asked.
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: TheUnexplained

Post by BruceSteers »

maybe there is a lf in the blank shell return

perharps something like this..

myip=""
While Not myip
  Wait 1 ' wait a second before each try
  Shell "hostname -I" To myip
  myip = Trim(myip) ' trim whitespace/LF
Wend

myip = Split(myip, " ")[0]

Print "this is my ip address: " & myip

If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 168
Joined: Saturday 4th September 2021 11:29pm

Re: TheUnexplained

Post by thatbruce »

Just for improvements sake:
Dim maxtries as Integer=100
Dim tries as Integer
myip=""
While Not myip
  If tries>maxtries then
    error.raise("No connection") ' or whatever is suitable
    break ' if you dont raise an error
  endif
  Inc tries
  Wait 0.25 ' I thought 1 second was a bit pessimistic
  Shell "hostname -I" To myip
  myip = Trim(myip) ' trim whitespace/LF
Wend
  ' and of course, if we still haven't got one
If not myip then
  ' die, with maximum noise
endif
 

but, mnyeh, that could probably be improved anyway

b
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: TheUnexplained

Post by BruceSteers »

other things to consider....

Sometimes a command works better if you use bash instead of the default sh shell, Don't ask me why.
In the following example i try to get the xdg videos dir first using the default gambas sh Shell , then i change to bash...


  Shell "source ~/.config/user-dirs.dirs\necho -n $XDG_VIDEOS_DIR" To sVids
  Print "sh command returns ";; sVids

' Now change gambas shell to use bash..
  System.Shell = System.Find("bash")

  Shell "source ~/.config/user-dirs.dirs\necho -n $XDG_VIDEOS_DIR" To sVids
  Print "bash command returns ";; sVids



sh command returns
bash command returns /home/bonus/Videos

And the other Bruce's suggestion of using a retry counter so the code does not get stuck in the loop if it never gets a result is very wise :)

Dim maxtries as Integer=100
Dim tries as Integer
myip=""
System.Shell = System.Find("bash") ' change to bash

While Not myip
  If tries>maxtries then
    error.raise("No connection") ' or whatever is suitable
    break ' if you dont raise an error
  Endif
  Inc tries
  Wait 0.25 ' I thought 1 second was a bit pessimistic
  Shell "hostname -I" To myip
  myip = Trim(myip) ' trim whitespace/LF
Wend
  ' and of course, if we still haven't got one
If not myip then
  ' die, with maximum noise
Endif
If at first you don't succeed , try doing something differently.
BruceS
Post Reply