WiFi alarm

For general Flowcode discussion that does not belong in the other sections.
RGV250
Posts: 282
http://meble-kuchenne.info.pl
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 31 times

Flowcode v10 WiFi alarm

Post by RGV250 »

Hi,
I was out and about when my phone told me I had used 80% of my data. It has got to be wrong I thought as I mainly use it at home on my broadband connection. When I got home I realised that it had not connected to the WiFi which is why I used all my data. The phone is about the only thing that connects to the WiFi so nothing else to alert me. It has probably been down for ages.

What I wondered is if anyone has any ideas how to monitor it, I plan to use an ESP32 and if there is no WiFi it starts bleeping. I did think on just pinging the router but thought that there night be a time when I can get a connection to the router but there is no internet. I did then think of using an NTP server as that should always be there but thought I would ask for suggestions.

Regards,
Bob

chipfryer27
Valued Contributor
Posts: 1320
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 321 times
Been thanked: 462 times

Re: WiFi alarm

Post by chipfryer27 »

Hi

As you rightly state, just because you have a WiFi signal it doesn't mean you have internet connectivity.

Some phones have a setting that you can choose to only use "data" over WiFi so that would be an obvious choice, with you having to change a setting to allow mobile data if required. Have a look through Wireless settings.

On my (all conquering) android it is in Settings > Connections > Data Usage > Mobile Data (which I can set)

Otherwise what you suggest isn't too bad an idea. Some routers though may allow you to poll for status, so that too may be an option. Pinging a remote service or such like is a sure fire way to know you have internet access.

Regards

RGV250
Posts: 282
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 31 times

Re: WiFi alarm

Post by RGV250 »

Hi Chipfryer,
I have just come across this which is how Windows does it.
https://superuser.com/questions/277923/ ... nection-re
Basically it tries to connect to this address http://www.msftncsi.com/ncsi.txt which has this text in the document Microsoft NCSI

The problem with setting to only use data over WiFi is I will forget when out and then wonder why I have no internet.

Bob

chipfryer27
Valued Contributor
Posts: 1320
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 321 times
Been thanked: 462 times

Re: WiFi alarm

Post by chipfryer27 »

Haha
The problem with setting to only use data over WiFi is I will forget when out and then wonder why I have no internet.
I have done the same. When abroad I use another phone with a local SIM and this acts as a hotspot allowing my UK phone / PC / whatever to access and I keep "data off" on my UK phone. More than once I've only had my UK phone as something at work needed access and I too subsequently needed access and forgotten, usually when trying to translate a menu or the like :)

Trying to connect to a known site would seem the best way and parsing a reply for "200 OK" or similar would be easy enough. Don't forget though that some routers automatically restart every x-days which kills connectivity for a minute or so therefore best not to set off a siren upon one failure :)

If using an esp32 then perhaps grabbing data from a NTP server would be of extra benefit as that could perhaps be used to sync it's RTC? Not sure of any that don't dump a ton of data you would need to retrieve / parse though.

Regards

RGV250
Posts: 282
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 31 times

Re: WiFi alarm

Post by RGV250 »

Good point, I had not thought of that, when I was with Plusnet I had a fixed IP. I will probably only check every couple of hours, it must have been out for quite a while as my data normally lasts a month easily and was used in just over a week.
Just looking for the "200 OK" is a lot simpler than getting the document and is all it needs really, I will have a play sometime soon.

Bob

chipfryer27
Valued Contributor
Posts: 1320
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 321 times
Been thanked: 462 times

Re: WiFi alarm

Post by chipfryer27 »

Hi

I think in a previous project you successfully grabbed "200 OK" or such like. Principle is the same, just choose a website that's likely to be available and of course even "400" is valid as the server has responded with it.

Regards

RGV250
Posts: 282
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 31 times

Re: WiFi alarm

Post by RGV250 »

I think in a previous project you successfully grabbed "200 OK" or such like.
Just what I was thinking.

Bob

RGV250
Posts: 282
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 31 times

Re: WiFi alarm

Post by RGV250 »

Hi,
I wonder if I have hit a snag, I have written a PHP script which gets gets the file and checked this works on my PC. The issue is that the PC has the Abyss web server so all is good. If I run it on the ESP32 and do not have the PC running I do not think it will work?
This is the script I have.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Download file</title>
</head>
<body>

<?php
$myfile = fopen("http://www.msftncsi.com/ncsi.txt", "r") or die("Unable to open file!");
$text = fread($myfile, 14);
fclose($myfile);

echo("<pre>$text</pre>");

//Test run - Localhost/download_file.php in browser.
?>
</body>
</html>


Bob

chipfryer27
Valued Contributor
Posts: 1320
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 321 times
Been thanked: 462 times

Re: WiFi alarm

Post by chipfryer27 »

Hi

Perhaps overthinking?

Maybe just use the "connect" macro within the component macro to connect to your chosen site. This will return 0 if unsuccessfull or 1 if all good?

Regards

chipfryer27
Valued Contributor
Posts: 1320
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 321 times
Been thanked: 462 times

Re: WiFi alarm

Post by chipfryer27 »

PS

I'd need to check the procedure to actually connect, it's most likely more than just connect :)

Post Reply