Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPClient.h and ArduinoHttpClient.h side by side #283

Closed
tkralj opened this issue May 18, 2019 · 24 comments
Closed

HTTPClient.h and ArduinoHttpClient.h side by side #283

tkralj opened this issue May 18, 2019 · 24 comments

Comments

@tkralj
Copy link

tkralj commented May 18, 2019

Hello. I would like to use HTTPClient.h and ArduinoHttpClient.h side by side. It seems that this two libs cannot co-exist together. I'm using HTTPClient.h with ESP32 to GET / POST but unfortunately I cannot use TinyGsm with this HTTPClient also. The problem is when I include ArduinoHttpClient.h i get compile errors:

The code is:
TinyGsmClientSecure client_gsm(modem);
const char server[] = "vsh.pp.ua";
const char resource[] = "/TinyGSM/logo.txt";
const int port = 443;
HttpClient http = HttpClient(client_gsm, server, port);

And the error i get:

networkgsm:24:54: error: invalid cast to abstract class type 'HttpClient'
HttpClient http (client_gsm, server, port);

Is there a way to get around it ?

@SRGDamia1
Copy link
Collaborator

What version of the ESP32 core are you using?

It is this problem: #269

@tkralj
Copy link
Author

tkralj commented May 18, 2019 via email

@SRGDamia1
Copy link
Collaborator

The compiler problems with the ESP32 and ESP8266 should now be fixed.

@uuperi
Copy link

uuperi commented May 23, 2019

The compiler problems with the ESP32 and ESP8266 should now be fixed.

I'm still getting the error with my ESP32 and SIM868

cannot declare variable 'http' to be of abstract type 'HttpClient'

@SRGDamia1
Copy link
Collaborator

Ok, sorry, I'm seeing the issue now. This isn't something TinyGSM can fix. The ArduinoHTTPClient library just isn't compatible with ESP32 core v1.0.2. The powers in the ESP32 world added extra virtual functions to their core Client.h that are not in the Arduino standard. That breaks compatibility with every other type of Arduino library that uses a Client. I overhauled TinyGSM to make it compatible with v1.0.2, but ArduinoHTTPClient isn't. You'll have to roll back to 1.0.1, comment out the extra virtual functions as here, or hand-do the http requests using a web client.

Also, I'd suggest commenting on the issue for the ESP32 core: espressif/arduino-esp32#2755

@tkralj
Copy link
Author

tkralj commented May 23, 2019 via email

@SRGDamia1
Copy link
Collaborator

It builds for me TinyGSM 0.7.4, ESP32 core v1.0.1, and ArduinoHttpClient 0.4.0. It also builds for me if I use ESP32 core v1.0.2 but comment out the two offending lines in Cores/esp32/Client.h.

@tkralj
Copy link
Author

tkralj commented May 23, 2019 via email

@tkralj
Copy link
Author

tkralj commented May 24, 2019 via email

@uuperi
Copy link

uuperi commented May 24, 2019

Hello Sara, it builds for me also but it does not work well. It's not problem with build. I can build and run code but code does not run as it should. Instead it loops without getting response even though TinyGSM downloaded the file because i can see it in debug mode.

I had the same problem. The build was fine with 1.0.1 and some of the ArduinoHttpClient's functions worked just as desired but when I tried to do a basic http GET-request with TinyGSM's example-sketch it gets stuck and never prints out the response. According to the debug output I believe it has something to do with the fact that ArduinoHttpClient is designed for 16 bit integers and ESP32 uses 32 bit integers.

@SRGDamia1
Copy link
Collaborator

SRGDamia1 commented May 24, 2019

I am working to solve the bugs with the SIM800, but I don't have time to work on specific ESP32 core library compatibility problems.

@uuperi
Copy link

uuperi commented May 27, 2019

It's not problem with build. I can build and run code but code does not run as it should. Instead it loops without getting response even though TinyGSM downloaded the file because i can see it in debug mode.

It seems like the problem is not just with the HttpClient, but also with the TinyGSM library since in the Diagnostics-sketch the code uses only TinyGSMClient to do the http-request but still can't print out the response body. Debug log shows the output just as supposed but you can't save it to any variable.

@uuperi
Copy link

uuperi commented May 27, 2019

It seems like the problem is not just with the HttpClient, but also with the TinyGSM library since in the Diagnostics-sketch the code uses only TinyGSMClient to do the http-request but still can't print out the response body. Debug log shows the output just as supposed but you can't save it to any variable.

Nevermind, I updated the library and it seems to be working now

@eabase
Copy link

eabase commented Jul 19, 2019

@uuperi Which library did you update? I get the same error today, using what is supposed to be the latest of both TinyGSM and ArduinoHTTPClient for an ESP32 based project, testing on the HttpClient.ino (from TinyGSM).

@uuperi
Copy link

uuperi commented Jul 19, 2019

@eabase the TinyGSM library. You are using ESP32 board version 1.0.1 right?

@eabase
Copy link

eabase commented Jul 22, 2019

@uuperi
yes

@alexandreberg
Copy link

Hi,

I am testing with platformIO: PLATFORM: Espressif 32 (2.0.0) > DOIT ESP32 DEVKIT V1
[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1]
With the libs
-- 1.2
| |-- 1.0
| |-- 1.0
| | |-- 1.0
|-- 0.10.9

And it doesn´t work.
GPRS connected
httpRequestData atualizaGrafico: api_key=xxxxxxxxp&value1=Sensor-01&value2=Sensor-02&value3=Sensor-03
[E][WiFiGeneric.cpp:654] hostByName(): DNS Failed for example.com
-1

Does anyone have any sugestion to posting http data over GPRS without using the HTTPClient.h library for ESP32 without have to downgrade the esp32 core?

Thanks.

@SRGDamia1
Copy link
Collaborator

@alexandreberg The issue being discussed here last summer was only an issue with core version 1.0.2, and the issue was related to compiling the library, not using it.

Based on the little bit you posted (ie, the reference to "WiFiGeneric.cpp) I'm guessing you're improperly trying to supply the esp core's wifi libraries with a GSM client. That will simply not work: #422 (comment)

@genotix
Copy link

genotix commented Jan 19, 2021

It would be very much appreciated if someone would have a combined example of:

  • Usage of the SIM800L
  • Doing a POST
  • Over HTTPS

I've been trying to combine the ArduinoHTTP requests and the one from TinyGSM but the latter only has a GET and the first seems to have issues working with the TinyGSMSecure variant.

Some help would be greatly appreciated.

@alexandreberg
Copy link

It would be very much appreciated if someone would have a combined example of:

  • Usage of the SIM800L
  • Doing a POST
  • Over HTTPS

I've been trying to combine the ArduinoHTTP requests and the one from TinyGSM but the latter only has a GET and the first seems to have issues working with the TinyGSMSecure variant.

Some help would be greatly appreciated.

Hi this example is working and makes a post with HTTPd, not HTTPS and sends data do a mysql database stored in BlueHost.
It runs on STM32 Bluepill, but works too on ESP32.
You can see de server side following the link bellow in RandomNerdTutorials that explains in detail.

The sketch:
#include <Arduino.h>
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-sim800l-publish-data-to-cloud/
*/

// Teste com buzzer
#define buzzer PB5

// Your GPRS credentials (leave empty, if not needed)
const char apn[] = "timbrasil.br"; // APN (example: internet.vodafone.pt) use https://wiki.apnchanger.org
const char gprsUser[] = "tim"; // GPRS User
const char gprsPass[] = "tim"; // GPRS Password

// SIM card PIN (leave empty, if not defined)
const char simPIN[] = "";

// Server details
// The server variable can be just a domain name or it can have a subdomain. It depends on the service you are using
const char server[] = "yourDomain.com.br"; // domain name: example.com, maker.ifttt.com, etc
const char resource[] = "/data/post-data.php"; // resource path, for example: /post-data.php
const int port = 80; // server port number

// Keep this API Key value to be compatible with the PHP code provided in the project page.
// If you change the apiKeyValue value, the PHP file /post-data.php also needs to have the same key
String apiKeyValue = "xxxxxxxxxxxxxx";

#define MODEM_RX PB10
#define MODEM_TX PB11
HardwareSerial Serial3(MODEM_TX, MODEM_RX);

// Set serial for debug console (to Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to SIM800 module)
#define SerialAT Serial3

// Configure TinyGSM library
#define TINY_GSM_MODEM_SIM800 // Modem is SIM800
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

// Define the serial console for debug prints, if needed
#define DUMP_AT_COMMANDS

#include <Wire.h>
#include <TinyGsmClient.h>

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif

// TinyGSM Client for Internet connection
TinyGsmClient client(modem);

#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds /
#define TIME_TO_SLEEP 3600 /
Time ESP32 will go to sleep (in seconds) 3600 seconds = 1 hour */

#define IP5306_ADDR 0x75
#define IP5306_REG_SYS_CTL0 0x00

void setup() {
// Set serial monitor debugging window baud rate to 115200
SerialMon.begin(115200);
Serial3.begin(115200); // the GPRS baud rate
Wire.begin();

//Buzzer
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, LOW);

delay(3000);

// Unlock your SIM card with a PIN if needed
if (strlen(simPIN) && modem.getSimStatus() != 3 ) {
modem.simUnlock(simPIN);
}
}

void loop() {

SerialMon.print("Connecting to APN: ");
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println("Connection to APN fail");
}
else {
SerialMon.println("Connection to APN OK");

SerialMon.print("Connecting to Server");
SerialMon.print(server);
if (!client.connect(server, port)) {
  SerialMon.println("Connection to Server fail");
}
else {
  SerialMon.println("Connection to Server OK");

  // Making an HTTP POST request
  SerialMon.println("Performing HTTP POST request...");
  // Prepare your HTTP POST request data (Temperature in Celsius degrees)
  ////String httpRequestData = "api_key=" + apiKeyValue + "&value1=" + String(bme.readTemperature())
                      ////   + "&value2=" + String(bme.readHumidity()) + "&value3=" + String(bme.readPressure()/100.0F) + "";
  // Prepare your HTTP POST request data (Temperature in Fahrenheit degrees)
  //String httpRequestData = "api_key=" + apiKeyValue + "&value1=" + String(1.8 * bme.readTemperature() + 32)
  //                       + "&value2=" + String(bme.readHumidity()) + "&value3=" + String(bme.readPressure()/100.0F) + "";
      
  // You can comment the httpRequestData variable above
  // then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)
  String httpRequestData = "api_key=xxxxxxxxxxxxxxx&value1=10&value2=33&value3=9999"; //this is just to test the connection with the server

  client.print(String("POST ") + resource + " HTTP/1.1\r\n");
  client.print(String("Host: ") + server + "\r\n");
  client.println("Connection: close");
  client.println("Content-Type: application/x-www-form-urlencoded");
  client.print("Content-Length: ");
  client.println(httpRequestData.length());
  client.println();
  client.println(httpRequestData);

  unsigned long timeout = millis();
  while (client.connected() && millis() - timeout < 10000L) {
    // Print available data (HTTP response from server)
    while (client.available()) {
      char c = client.read();
      SerialMon.print(c);
      timeout = millis();
    }
  }
  SerialMon.println();

  // Close client and disconnect
  client.stop();
  SerialMon.println(F("Server disconnected"));
  modem.gprsDisconnect();
  SerialMon.println(F("GPRS disconnected"));
  //bipa para dizer que transmitiu
  digitalWrite(buzzer, HIGH);
  delay(100);
  digitalWrite(buzzer, LOW);
  delay(180000);
}

}
}

platformio.ini file:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:bluepill_f103c8] ;STM32duino
platform = ststm32 ;STM32duino
board = bluepill_f103c8 ;STM32duino
framework = arduino
monitor_port = COM5
monitor_speed = 115200
upload_port = COM5
upload_speed = 921600
upload_protocol = serial ;para FTDI (RX - A9, TX - A10, GND - GND, 5V - 5V)
lib_ldf_mode = deep+

lib_deps =
vshymanskyy/TinyGSM @ 0.10.9
vshymanskyy/StreamDebugger @ 1.0.1
adafruit/RTClib @ ~1.12.4

Hope it may help you.

@Toumal
Copy link

Toumal commented Feb 5, 2021

It would be very much appreciated if someone would have a combined example of:

  • Usage of the SIM800L
  • Doing a POST
  • Over HTTPS

I've been trying to combine the ArduinoHTTP requests and the one from TinyGSM but the latter only has a GET and the first seems to have issues working with the TinyGSMSecure variant.

Some help would be greatly appreciated.

I have to echo this request. I am running against walls trying to get HTTPS to work in any way.
Yes, HTTP works. Please don't post examples for http.

@genotix
Copy link

genotix commented Feb 5, 2021

It would be very much appreciated if someone would have a combined example of:

  • Usage of the SIM800L
  • Doing a POST
  • Over HTTPS

I've been trying to combine the ArduinoHTTP requests and the one from TinyGSM but the latter only has a GET and the first seems to have issues working with the TinyGSMSecure variant.
Some help would be greatly appreciated.

I have to echo this request. I am running against walls trying to get HTTPS to work in any way.
Yes, HTTP works. Please don't post examples for http.

I have spent over 2,5 week finding a way to get this to work properly.
Eventually I have integrated the SSLClient library with the TinyGSM code.
I advise you to do the same.

Since I developed this for my company, I'm not at liberty to share any code with you.

@datamann
Copy link

datamann commented Feb 5, 2021

@genotix Nice of you to take advantage of other people's work but not to share back. That's the way to keep open source alive and kicking....

@genotix
Copy link

genotix commented Feb 5, 2021

@datamann, as you can see on my profile I will share sourcecode when I develop something myself or when I extend sources of others. I have been doing so way before Github even existed and I am very well aware of the GNU/GPL.

This is a contribution I did in 2003 on the Gentoo platform:
https://forums.gentoo.org/viewtopic-t-113911.html
Yes, USB was new to Linux then.

As I said, in this case I am not allowed to submit sourcecode, I simply am not at liberty. I contribute my part to the community, just you worry about your own contributions. I have spent reading about 2000 articles for 2,5 weeks and ended up writing a very specific implementation in 2,5 days with the tip I provided above.
(Adding SPIFFS certificate storage and a shitload of other things; the implementation was merely a small percentage)

I just saved you about 15 days, start coding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants