0

Want Feather MO WIFI To GOTO a Web Page
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Want Feather MO WIFI To GOTO a Web Page

by _phillip on Tue Jun 15, 2021 10:20 pm

I am searching for a way to send a text when my Feather MO WIFI loses its wifi connection.

I have a php web page with a script that texts a certain cell phone (mine, in this case). The php script works. No problem with that.

My problem is how do I get the the Feather to launch that particular webpage? I do not want to send the webpage data or anything of the sort. I just want it to go to the php web page. Once the web page is open, the text will be sent.

I believe that the Feather will have to become server for this to work.

Thank you for any help you can provide.

_phillip
 
Posts: 132
Joined: Fri Apr 09, 2021 3:28 pm

Re: Want Feather MO WIFI To GOTO a Web Page

by dastels on Wed Jun 16, 2021 8:20 am

I see a couple problems:

1. To run the feather as the server with that page means that it would have to be running PHP.

2. If it's lost it's wifi connection, it's offline and can't access the internet or your local network.

Dave

dastels
 
Posts: 6773
Joined: Tue Oct 20, 2015 3:22 pm

Re: Want Feather MO WIFI To GOTO a Web Page

by BryonMiller on Wed Jun 16, 2021 9:15 am

Dave made two points.

The second point, regarding not having a connection so you can't got to a web page, is the tough one to get around. All you can do is try to re-establish the wifi connection and then send your message that "the connection was lost - but now its back".

The other issue about "going to a web page" is fairly easy. You don't need to be a server (although being a non-php server is pretty easy) you just need to make a HTTP GET request. Here is a snippet of code I use to do something very similar. Couple of differences are I am using an asp script rather than a php script and I am telling my server script what the subject should be and what the message is that I want it to send.

Code: Select all | TOGGLE FULL SIZE
mainPumpWarnEmailSent = true;
Serial.println("Send email regarding Main Pump Fail!");
overrideWatchdogsec = 20;  // tell interrupt  routine to keep watchdog happy
if (emailClient.connect(emailServer, 80)) // associated DNS can block 20 seconds
     {
     overrideWatchdogsec = 1;
     timeToRequestWAN=now+deltaWANtime;
     emailWasConnected = true;
     Serial.println("connected to emailServer");
     // Make a HTTP request:
     emailClient.print("GET /arduino/email/email.asp?msg=MAIN%20FAIL&sub=SumpPump&email=");
     if (emailEnable)
          emailClient.print("true");
     else emailClient.print("false");
     emailClient.print("&text=");
     if (textEnable)
          emailClient.print("true");
     else emailClient.print("false");
     emailClient.println(" HTTP/1.1");
     emailClient.println("Host: http://www.yourwebserver.com");
     emailClient.println("Connection: close");
     emailClient.println();
     }
else //if you couldn't make a connection:
     Serial.println("email sending connection failed");

For this to work emailServer should be set equal to something like "www.yourwebserver.com" and the script should be located at the page "/arduino/email/email.asp". You are, of course, free to change these particulars to match you actual URL.

You might also note that if you have a watchdog running you need to be prepared for an unusually long code block.

Hope this helps,
Bryon

BryonMiller
 
Posts: 211
Joined: Fri Mar 04, 2016 10:34 am

Re: Want Feather MO WIFI To GOTO a Web Page

by _phillip on Wed Jun 16, 2021 10:15 am

dastels wrote:I see a couple problems:

1. To run the feather as the server with that page means that it would have to be running PHP.

2. If it's lost it's wifi connection, it's offline and can't access the internet or your local network.

Dave


Dave, thanks for getting back to me.

As to (1): This entire site is built on PHP, so no problem there.

As to (2): Aaarghh!!!!!I #@!|&|/?#@!!!! You'r right! I'll go stand in the corner now.

I have had the experience (in this area) of losing wifi and still having power. But, again, just as you pointed out, no wifi, no message sent. My Feather board has a nice Adafruit LiPo that will still allow us to read pertinent data on the LCD built into the enclosure door. So the vital info is still accessible, but no ability to know that wifi has been lost. Bummer.

I had some nice (partial) PHP code (seen next) that would trigger the PHP web page made for this occasion, but guess I'll have to toss into the trash bin.

Code: Select all | TOGGLE FULL SIZE
if (client.connect(server, 80)) {
    client.println("POST /test/post.php HTTP/1.1");
    client.println("Host: www.elithecomputerguy.com");
    .
   .
  }

Thanks for giving my chain a good yank.

_phillip
 
Posts: 132
Joined: Fri Apr 09, 2021 3:28 pm

Re: Want Feather MO WIFI To GOTO a Web Page

by dastels on Wed Jun 16, 2021 10:32 am

Re 1. I mean PHP would need to be running on the Feather since PHP is server side.

Re 2: you could cache data while the connect is down and send it out once it's reesetablished. If you absolutely can't loose data and any sort of network is involved, you'll want to design that in from the start.

Dave

dastels
 
Posts: 6773
Joined: Tue Oct 20, 2015 3:22 pm

Re: Want Feather MO WIFI To GOTO a Web Page

by _phillip on Wed Jun 16, 2021 7:33 pm

@ByronMiller

Thank you so much for your in-depth post. I really appreciate your kindness in posting all of the code that you did.

I have been working with a similar sketch, but while I can get on wifi (after some tweaking) with it, I am not triggering the tank-data.php page. I'm sure that my web page referencing is incorrect. Or something else is incorrect.

Here is my modified sketch:
Code: Select all | TOGGLE FULL SIZE
#include <WiFi101.h>

  //#define sensorPin A5

  //************************* WiFI Setup **************************************
  #define WINC_CS   8
  #define WINC_IRQ  7
  #define WINC_RST  4
  #define WINC_EN   2

  char ssid[] = "XxXx"; 
  char pass[] = "";

  int status = WL_IDLE_STATUS;

  char server[] = "www.talaveramdwca.org";

  WiFiClient client;

void setup() {

  Serial.begin(9600);

  WiFi.setPins(WINC_CS, WINC_IRQ, WINC_RST, WINC_EN);
 
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }

  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  IPAddress gateway = WiFi.gatewayIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
}

void loop() {

  if (client.connect(server, 80)) {

    client.println("POST /tank-data.php HTTP/1.1");
   
    client.println("Host: www.talaveramdwca.org");
    client.println("Content-Type: application/x-www-form-urlencoded");
  }

  if (client.connected()) {
    client.stop();
  }

  delay(3000);
}

This sketch was originally meant to post sensor data on a webpage. I stripped out all of that code because all I want the sketch to do is GO to the page. That would be sufficient to trigger the PHP script that sends the text.

Thanks for your help.

_phillip
 
Posts: 132
Joined: Fri Apr 09, 2021 3:28 pm

Re: Want Feather MO WIFI To GOTO a Web Page

by _phillip on Wed Jun 16, 2021 10:55 pm

Well, shocker! The sketch I posted above did work ... but, it only took 30-35 minutes to receive the text. Not too handy. LOL!

Back to the drawing board.

_phillip
 
Posts: 132
Joined: Fri Apr 09, 2021 3:28 pm

Please be positive and constructive with your questions and comments.