TheUnexplained

Post

Posted
Rating:
#1 (In Topic #1169)
Trainee
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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 How are you getting and inserting the ip address?
what method exactly?
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
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.

<IMG src="https://www.cogier.com/gambas/Startups.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#4
Trainee

BruceSteers said

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.
Online now: No Back to the top

Post

Posted
Rating:
#5
Trainee

cogier said

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.

<IMG src="https://www.cogier.com/gambas/Startups.png"> </IMG>

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.
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
maybe there is a lf in the blank shell return

perharps something like this..

Code (gambas)

  1.  
  2. myip=""
  3. While Not myip
  4.   Wait 1 ' wait a second before each try
  5.   Shell "hostname -I" To myip
  6.   myip = Trim(myip) ' trim whitespace/LF
  7.  
  8. myip = Split(myip, " ")[0]
  9.  
  10. Print "this is my ip address: " & myip
  11.  
  12.  
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Just for improvements sake:

Code (gambas)

  1. Dim maxtries as Integer=100
  2. Dim tries as Integer
  3. myip=""
  4. While Not myip
  5.   If tries>maxtries then
  6.     error.raise("No connection") ' or whatever is suitable
  7.     break ' if you dont raise an error
  8.   Inc tries
  9.   Wait 0.25 ' I thought 1 second was a bit pessimistic
  10.   Shell "hostname -I" To myip
  11.   myip = Trim(myip) ' trim whitespace/LF
  12.   ' and of course, if we still haven't got one
  13. If not myip then
  14.   ' die, with maximum noise
  15.  
but, mnyeh, that could probably be improved anyway

b

Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
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…

Code (gambas)

  1.  
  2.   Shell "source ~/.config/user-dirs.dirs\necho -n $XDG_VIDEOS_DIR" To sVids
  3.   Print "sh command returns ";; sVids
  4.  
  5. ' Now change gambas shell to use bash..
  6.   System.Shell = System.Find("bash")
  7.  
  8.   Shell "source ~/.config/user-dirs.dirs\necho -n $XDG_VIDEOS_DIR" To sVids
  9.   Print "bash command returns ";; sVids
  10.  
  11.  

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 :)

Code (gambas)

  1. Dim maxtries as Integer=100
  2. Dim tries as Integer
  3. myip=""
  4. System.Shell = System.Find("bash") ' change to bash
  5.  
  6. While Not myip
  7.   If tries>maxtries then
  8.     error.raise("No connection") ' or whatever is suitable
  9.     break ' if you dont raise an error
  10.   Inc tries
  11.   Wait 0.25 ' I thought 1 second was a bit pessimistic
  12.   Shell "hostname -I" To myip
  13.   myip = Trim(myip) ' trim whitespace/LF
  14.   ' and of course, if we still haven't got one
  15. If not myip then
  16.   ' die, with maximum noise
  17.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.