Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Pushover https post request #21

Closed
DavidAntonin opened this issue Oct 20, 2021 · 16 comments
Closed

Pushover https post request #21

DavidAntonin opened this issue Oct 20, 2021 · 16 comments
Labels
Support Library support wontfix This will not be worked on

Comments

@DavidAntonin
Copy link

Hi, I have read all the information regarding https so I know that it is not currently possible to implement it on esp8266. Unfortunately the Pushover service only accepts POST to https://api.pushover.net/1/messages.json. One library for ESP8266 solves this on the client with setInsecure(). Would it not be possible to implement this as well?
Thank you

@khoih-prog
Copy link
Owner

Thanks for your interest in the library.

As you know, this library is designed for HTTP request only, and HTTPS is not implemented now.

However, I'm currently working on and already successful in making a twin library (AsyncHTTPSRequest_Generic) to deal with HTTPS only, but just working OK so far with ESP32. It'll take some time to fully test and publish it. Making it supporting to ESP8266, STM32 and many other boards, if easily possible and time-permitted, is in my plan.

You certainly can use normal secure sync WebClient for those services using only HTTPS, and setInsecure() can be easily used, but it's just a kludge and not advisable (unless it's absolutely necessary without any better choice) as real certificate checking is bypassed.

Anyway. I'm closing the issue now because HTTPS won't be supported by this library.

@khoih-prog khoih-prog added Support Library support wontfix This will not be worked on labels Oct 20, 2021
@DavidAntonin
Copy link
Author

DavidAntonin commented Oct 21, 2021 via email

@khoih-prog
Copy link
Owner

FYI

The first library in the AsyncSSL series has been published

  1. AsyncTCP_SSL to support only ESP32

The next one

  1. AsyncHTTPSRequest_Generic will be released tomorow, just supporting only ESP32.

@khoih-prog
Copy link
Owner

AsyncHTTPSRequest_Generic has just been released, just supporting only ESP32.

You'd better try and switch to ESP32 if can't wait for ESP8266 support (currently without time-frame yet)

@DavidAntonin
Copy link
Author

DavidAntonin commented Jan 23, 2022 via email

@khoih-prog
Copy link
Owner

Sorry I don't have time to help you solve your special use-case issue.

Just some quick idea that you wrongly design your mission-critical system, by failing to use powerful ESP32 multitasking RTOS and/or Timer Interrupt.

If you don't know how to start, check

  1. Async_ESP32_MultiTask example, which is written to use prioritized multi-tasks for blocking Blynk
  2. ESP32_New_TimerInterrupt library

Libraries are written for many boards / platforms, for general use-case to demonstrate how to use basic libraries' features. So don't expect to use directly to any use-case without having good design, depending on the board / platform.

If you still have more issues, please post and ask for help on Arduino / ESP32 Forum.

@DavidAntonin
Copy link
Author

Thank you for a fast reply. So only few qustions to libraries:

  • It is possible to use AsyncHTTPRequest_Generic and AsyncHTTPSRequest_Generic together on ESP32?
  • It is possible to send second http request while the first still did not get response? If I understand it correctly, this is not possible, because the new request can not be sent until readyState == 4 (complete with response received)
    Thank you

@khoih-prog
Copy link
Owner

It is possible to use AsyncHTTPRequest_Generic and AsyncHTTPSRequest_Generic together on ESP32?

I haven't tested but guessed that there will be some conflicts. Why not using the better HTTPS only?

Possibly in the future, I'll add feature into AsyncHTTPSRequest_Generic to permit you to do both HTTP and HTTPS.

It is possible to send second http request while the first still did not get response?

I don't see why not as this is Async, not Sync. You don't need to wait for any response, but just receive and process the responses when they comes.

Certainly it depends on how you write your code, which can destroy the Async features of the library.

@DavidAntonin
Copy link
Author

DavidAntonin commented Jan 24, 2022

I tried a simple modification of your basic example for ESP. I added monitoring of readyState to see how long sending a receiving took. Request can be sent when readyState is readyStateUnsent (0) or readyStateDone (4). In my testing i get only values 0,1,4 - 4 is on receiving the response. So I investigate I can only send another request when I receive a response.

#if !( defined(ESP8266) ||  defined(ESP32) )
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
#endif

// Level from 0-4
#define ASYNC_HTTP_DEBUG_PORT     Serial
#define _ASYNC_HTTP_LOGLEVEL_     1

// 300s = 5 minutes to not flooding
#define HTTP_REQUEST_INTERVAL     60  //300

// 10s
#define HEARTBEAT_INTERVAL        10

int status;     // the Wifi radio's status

const char* ssid        = "***";
const char* password    = "***";
int lastReadySt = 99;

#if (ESP8266)
#include <ESP8266WiFi.h>
#elif (ESP32)
#include <WiFi.h>
#endif

#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET      "AsyncHTTPRequest_Generic v1.5.0"
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN             1005000

#include <AsyncHTTPRequest_Generic.h>             // https://github.com/khoih-prog/AsyncHTTPRequest_Generic

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include <AsyncHTTPRequest_Impl_Generic.h>        // https://github.com/khoih-prog/AsyncHTTPRequest_Generic

#include <Ticker.h>

AsyncHTTPRequest request;
Ticker ticker;
Ticker ticker1;

void heartBeatPrint(void)
{
  static int num = 1;

  if (WiFi.status() == WL_CONNECTED)
    Serial.print(F("H"));        // H means connected to WiFi
  else
    Serial.print(F("F"));        // F means not connected to WiFi

  if (num == 80)
  {
    Serial.println();
    num = 1;
  }
  else if (num++ % 10 == 0)
  {
    Serial.print(F(" "));
  }
}

void sendRequest()
{
  static bool requestOpenResult;

  if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
  {
    //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
    requestOpenResult = request.open("GET", "http://copnb.cz/test/time.php");

    if (requestOpenResult)
    {
      // Only send() if open() returns true, or crash
      request.send();
      Serial.printf("%i - request sent\n", millis());
    }
    else
    {
      Serial.println("Can't send bad request");
    }
  }
  else
  {
    Serial.println("Can't send request");
  }
}

void requestCB(void* optParm, AsyncHTTPRequest* request, int readyState)
{
  (void) optParm;

  if (readyState == readyStateDone)
  {
    Serial.printf("%i - response received\n", millis());
    Serial.println("\n**************************************");
    Serial.println(request->responseText());
    Serial.println("**************************************");

    request->setDebug(false);
  }
}

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial);

  Serial.println("\nStarting AsyncHTTPRequest_ESP using " + String(ARDUINO_BOARD));
  Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);

  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid, password);

  Serial.println("Connecting to WiFi SSID: " + String(ssid));

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }

  Serial.print(F("AsyncHTTPRequest @ IP : "));
  Serial.println(WiFi.localIP());

  request.setDebug(false);

  request.onReadyStateChange(requestCB);
  ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest);

  ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint);

  // Send first request now
  sendRequest();
}

void loop()
{
  if  (lastReadySt != request.readyState())
  {
    Serial.printf("%i - readyState = %i \n", millis(), request.readyState());
    lastReadySt = request.readyState();
  }

}

@khoih-prog
Copy link
Owner

khoih-prog commented Feb 25, 2022

Hi @DavidAntonin

Sorry for forgetting the issue for some time

As you can see in the example

void sendRequest()
{
  static bool requestOpenResult;

  if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
  {
     ...
  }
  else
  {
    Serial.println("Can't send request");
  }
}

The request can only be sent if (request.readyState() == readyStateUnsent or request.readyState() == readyStateDone. So the result you got is quite expected.

The example is just example, to show how you can basically use some library's functions. You have to adapt for using in your complex use-case.

Try to drop

 if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)

and see if it's OK

@DavidAntonin
Copy link
Author

Hello, thank you for your answear. I know about (request.readyState() == readyStateUnsent or request.readyState() == readyStateDone It is not problem. Problem is I cannot send even if readyStateDone. Please see my last 2 posts in #khoih-prog/AsyncHTTPSRequest_Generic#4 and my investigations. Can you try it yourselve? Send second request to different url (than the first request) trigered by readyStateDone of the first request. Thank you

@khoih-prog
Copy link
Owner

OK, For AsyncHTTPRequest_Generic, I can duplicate the issue now if sending to different address. Same address is OK with multiple requests.

Will spend time to identify the culprit and fix, if possible.

As this is the almost the same code as asyncHTTPrequest library for ESP32/ESP8266, can you also post the issue on that library as the original author must have the better knowledge to solve for ESP boards.

@khoih-prog
Copy link
Owner

khoih-prog commented Feb 26, 2022

I just write a new example to permit to send AsyncHTTPRequest to multiple different addresses. Will post a new release soon for this library as well as a new release for AsyncHTTPSRequest_Generic library to fix Cannot send requests to different addresses #4

The terminal output will show you the requests are sent and received correctly

Starting AsyncHTTPRequest_ESP_Multi using ESP32_DEV
AsyncHTTPRequest_Generic v1.7.1
Connecting to WiFi SSID: HueNet1
.......
AsyncHTTPSRequest @ IP : 192.168.2.88

Sending request: http://worldtimeapi.org/api/timezone/Europe/Prague.txt

Sending request: http://www.myexternalip.com/raw

**************************************
abbreviation: CET
client_ip: aaa.bbb.ccc.ddd
datetime: 2022-02-26T01:54:15.753826+01:00
day_of_week: 6
day_of_year: 57
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: 3600
timezone: Europe/Prague
unixtime: 1645836855
utc_datetime: 2022-02-26T00:54:15.753826+00:00
utc_offset: +01:00
week_number: 8
**************************************

**************************************
aaa.bbb.ccc.ddd
**************************************

Sending request: http://worldtimeapi.org/api/timezone/America/Toronto.txt

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2022-02-25T19:54:15.822746-05:00
day_of_week: 5
day_of_year: 56
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1645836855
utc_datetime: 2022-02-26T00:54:15.822746+00:00
utc_offset: -05:00
week_number: 8
**************************************
HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH 
Sending request: http://worldtimeapi.org/api/timezone/Europe/Prague.txt

Sending request: http://www.myexternalip.com/raw

**************************************
aaa.bbb.ccc.ddd
**************************************

**************************************
abbreviation: CET
client_ip: aaa.bbb.ccc.ddd
datetime: 2022-02-26T01:59:15.745874+01:00
day_of_week: 6
day_of_year: 57
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: 3600
timezone: Europe/Prague
unixtime: 1645837155
utc_datetime: 2022-02-26T00:59:15.745874+00:00
utc_offset: +01:00
week_number: 8
**************************************

Sending request: http://worldtimeapi.org/api/timezone/America/Toronto.txt

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2022-02-25T19:59:15.804270-05:00
day_of_week: 5
day_of_year: 56
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1645837155
utc_datetime: 2022-02-26T00:59:15.804270+00:00
utc_offset: -05:00
week_number: 8
**************************************
HHH

@khoih-prog
Copy link
Owner

Hi @DavidAntonin

The new AsyncHTTPRequest_Generic releases v1.7.1 has just been published. Your contribution is noted in Contributions and Thanks

Please try the new example AsyncHTTPRequest_ESP_Multi which demonstrates how to send requests to multiple addresses and receive responses from them.

Best Regards,


Releases v1.7.1

  1. Add example AsyncHTTPRequest_ESP_Multi to demo connection to multiple addresses.
  2. Update Packages' Patches

@khoih-prog
Copy link
Owner

  • It is possible to use AsyncHTTPRequest_Generic and AsyncHTTPSRequest_Generic together on ESP32?

I just finished rewriting and testing the AsyncHTTPSRequest_Generic library to permit coexistence of AsyncHTTPRequest_Generic and AsyncHTTPSRequest_Generic

Will release within several hours. Cheers.

Now you can send HTTP and HTTPS requests to multiple addresses and receive responses from them.


Releases v2.0.0 of AsyncHTTPSRequest_Generic library

  1. Breaking change to permit coexisting with AsyncHTTPRequest library to send and receive both HTTP and HTTPS.
  2. Add example AsyncHTTP_HTTPSRequest_ESP to demonstrate how to send HTTP and HTTPS requests to multiple addresses and receive responses from them.

@khoih-prog
Copy link
Owner

Hi @DavidAntonin

The new AsyncHTTPSRequest_Generic releases v2.0.0 has just been published. Your contribution is noted in Contributions and Thanks

Please try the new example AsyncHTTP_HTTPSRequest_ESP which demonstrates how to send HTTP and HTTPS requests to multiple addresses and receive responses from them.

Best Regards,


Releases v2.0.0

  1. Breaking change to permit coexisting with AsyncHTTPRequest library to send and receive both HTTP and HTTPS.
  2. Add example AsyncHTTP_HTTPSRequest_ESP to demonstrate how to send HTTP and HTTPS requests to multiple addresses and receive responses from them.

khoih-prog added a commit that referenced this issue Feb 1, 2023
### Releases v1.13.0

1. Add support to ESP32 boards using `LwIP W6100 Ethernet`
2. Fix bug of `_parseURL()`. Check [Bug with _parseURL() #21](khoih-prog/AsyncHTTPSRequest_Generic#21)
3. Improve `README.md` so that links can be used in other sites, such as `PIO`
khoih-prog added a commit that referenced this issue Feb 1, 2023
### Releases v1.13.0

1. Add support to ESP32 boards using `LwIP W6100 Ethernet`
2. Fix bug of `_parseURL()`. Check [Bug with _parseURL() #21](khoih-prog/AsyncHTTPSRequest_Generic#21)
3. Improve `README.md` so that links can be used in other sites, such as `PIO`
khoih-prog added a commit that referenced this issue Feb 1, 2023
### Releases v1.13.0

1. Add support to ESP32 boards using `LwIP W6100 Ethernet`
2. Fix bug of `_parseURL()`. Check [Bug with _parseURL() #21](khoih-prog/AsyncHTTPSRequest_Generic#21)
3. Improve `README.md` so that links can be used in other sites, such as `PIO`
khoih-prog added a commit that referenced this issue Feb 1, 2023
### Releases v1.13.0

1. Add support to ESP32 boards using `LwIP W6100 Ethernet`
2. Fix bug of `_parseURL()`. Check [Bug with _parseURL() #21](khoih-prog/AsyncHTTPSRequest_Generic#21)
3. Improve `README.md` so that links can be used in other sites, such as `PIO`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Support Library support wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants