Cannot Receive Texts From HTTPS Website

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
_phillip
 
Posts: 313
Joined: Fri Apr 09, 2021 3:28 pm

Cannot Receive Texts From HTTPS Website

Post by _phillip »

Greetings,
This is a continuation of my original text sending problem but that thread has been 'Locked'. No problem.

Background
I have developed a Feather MO WIFI based control system that monitors water tank levels for my water association. The most important feature of this project is that texts are sent whenever water levels fall below 8 feet. I can do this 24/7 if I use an unsecure - HTTP - website, but if I use the water associations secure - HTTPS - website, the texts are never sent.

Update
I have learned that by changing a single line of code I can receive texts from the HTTPS website without fail. By changing -

Code: Select all

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

Code: Select all

if (client.connectSSL(server, 443))
the text is sent from the HTTPS site.

Here is the pertinent code from the test sketch:

Code: Select all

void loop() {

      postData = postVariable + " 7.5 feet";
      
      { 
          //if (client.connect(server, 80))    // use for HTTP sites  only ...
          if (client.connectSSL(server, 443))   // use for HTTPS site only ...
	   {
            client.println("POST /includes/text_message_to_be_sent.php HTTP/1.1");
            
            client.println("Host: www.secure-website.org");
            //client.println("Host: www.nonsecure-website.com"); 
            
            client.println("Content-Type: application/x-www-form-urlencoded");
            client.print("Content-Length: ");
            client.println(postData.length());
            client.println();
            client.print(postData);
            Serial.println("Message sent!");
          }

          if (client.connected()) {
            client.stop();
          }
          delay(60000);
      } 
      Serial.println(postData);      
      delay(3000);
    }
As noted the above code works perfectly for sending texts from either HTTP or HTTPS websites.

Using the sketch that has been uploaded to the Feather MO WIFI embedded in the project enclosure, I can receive texts from an HTTP site, but never from the water associations HTTPS website. Here is the code snippet from the embedded Feather sketch:

Code: Select all

void send_text(float interval, float tank_level){

    String current_tank_level = String (tank_level,2);

    postData = postVariable + current_tank_level; // using a variable for tank level ... 
      
    unsigned long tank_level_currentMillis = millis();  
      
    if (tank_level_currentMillis - tank_level_previousMillis >= interval) 
      { 
        tank_level_previousMillis = tank_level_currentMillis;
      
        if (client.connect(server, 80)) 		// HTTP site only ...
        //if (client.connectSSL(server, 443)) 	// HTTP site only ...
            {
              client.println("POST /includes/send_this_text_message.php HTTP/1.1");

              //client.println("Host: www.secure-website.org"); 
              client.println( "Host: www.non-secure-website.com" );

              client.println( "Content-Type: application/x-www-form-urlencoded" );
              client.print("Content-Length: ");
              client.println(postData.length());
              client.println();
              client.print(postData);

              Serial.println("Email Sent");
              Serial.println(postData);
            }

            if (client.connected()) {
                client.stop();
             }
      }
  }
The code snippet receives two variables: interval and tank_level. Interval is the time interval between each text message, 2 minutes in this case. 'tank_level' is the water tank level.

Bottom Line
Using my test sketch I can receive texts from either HTTP or HTTPS websites.
Using the embedded Feather sketch I can receive texts from an HTTP site but never from an HTTPS website.

For the sake of clarity I will mention the following:
The PHP files used in both sketches are identical. They are copies of each other.

I do not understand what I am overlooking. If someone can shed some light on this problem I would be very grateful.

Thank you.

User avatar
princessdoll39
 
Posts: 1
Joined: Wed Dec 14, 2022 2:40 pm

Re: Cannot Receive Texts From HTTPS Website

Post by princessdoll39 »

In a similar vein, I would want to learn more about this. Do you know how to fix this Error? I am curious to know what the answer is.

Locked
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”