Android Question Ethernet disconnects on reboot

rworner

Member
Licensed User
Longtime User
I am designing for a rooted MK802IIIS Android Mini PC. The devices use a wired ethernet connection (via USB to ethernet adapter) because WiFi is spotty in the areas the monitors are located. The App creates a webview and refreshes the webpage every 90 seconds to get near real time updates. Originally I used timers for all of the processes and when everything works as expected on the web side the displays work great. The screens are mounted about 10 feet above the floor, so I reboot the device once a day (via a service) so that no one needs to climb a ladder if the device should "hang". Prior to using a service I just used a timer for the reboot, but have had a couple occasions where the device returns to the home screen when there is a synchronization issue caused by the website net-scaler (the website is on 3 servers and automatically routes the request to the least used server). After the change to a service, the device reboots consistently, however after the reboot it loses the wired ethernet connection. I am attempting to add a second service >> to re-establish the wired ethernet connection at startup. The code includes a check for the ethernet connection (IF MyLan.GetMyIP<>"127.0.0.1" then ...) but even when there is no connection (Settings shows 0.0.0.0) the code returns true and continues to try to display the webpage. The information is from http://stackoverflow.com/questions/...net-how-to-toggle-ethernet-connectivity-state

Any suggestions would be greatly appreciated.
 

Attachments

  • reconnect.zip
    96.6 KB · Views: 198

rworner

Member
Licensed User
Longtime User
You can run these commands with a script: Running shell commands as SuperUser

I am trying run it as a script - within a service. But it does not restart the ethernet connection.

B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region
 
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
 
End Sub
Sub Service_Create
Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
Dim Ph As Phone
StdOut.Initialize
StdErr.Initialize
 
Runner = File.Combine(File.DirInternalCache, "runner")
Command = File.Combine(File.DirInternalCache, "command")
File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
'Any commands via crlf, and exit at end
File.WriteString(File.DirInternalCache, "command",  "ifconfig eth0 down"  & CRLF & " ifconfig eth0 up"  & CRLF & "exit")
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
End Sub
 
Sub Service_Start (StartingIntent As Intent)
 
End Sub
 
Sub Service_Destroy
 
End Sub
 
Upvote 0

rworner

Member
Licensed User
Longtime User
Check StdOut and StdErr.

I am thinking of going a different way with this. First, let me state that the WEBVIEW I create is the only app running on these devices. Currently my timers work to update the page and reboot the device without losing the ethernet connection. The problem comes when the update routine tries to load from a server that is out of sync. When that happens, the APP disappears and the Android desktop is visible. I am thinking I can create a service to perform a callsub: [Would it be CallSub(Main.Timer4) or CallSub(Main.Timer4_tick)?]. Where the code in Timer4_tick "refreshes" the webview:
B4X:
Webview1.BringToFront
Webview1.Enabled=True
Webview1.RemoveView
Activity.AddView(Webview1,0,0,100%x,100%y)
Webview1.LoadUrl(myUrl)
Webview1.Visible=True
Webview1.BringToFront
 
Upvote 0

rworner

Member
Licensed User
Longtime User
How is the WebView related to the ethernet connection?

The ethernet connection must exist for the webview to display. My thinking was that if I can refresh the webview the LoadUrl will try to redisplay the data. (I tried it - it did not work). The problem now appears that the app is "paused". Is there a way to "unpause" an app programatically?
 
Upvote 0

rworner

Member
Licensed User
Longtime User
WebView doesn't do anything special.

How is your program implemented? Activities are paused when they are not visible.
The app is designed as start on boot. After it is installed and started it creates a webview which refreshes itself every 90 seconds via a timer. Likewise a second timer reboots the device once a day which restarts the app on boot. Most of the devices in use have worked as expected for 27 days so far, however I have a few devices that when they perform the 90 second update are errorring out. This error results in the app being put into a paused state and the monitor displays the android desktop instead of the webview. I thought by adding a service that runs every couple of hours and calling the refresh webview sub that I could recover from the paused state. However what I have tried failed so far. So I am back to is there a way to un-pause a paused app?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Are you calling Service.StartForeground?

Are you familiar with the UI Cloud? It is an app that runs on real devices. The app usually runs for months without failures.

However as a precaution measure there is another app that "starts" the first app every minute. If the first app is already running then nothing happens. If it crashed then it will start again.
 
Upvote 0
Top