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

[E][HTTPClient.cpp:251] beginInternal(): failed to parse protocol #99

Closed
simogaspa84 opened this issue Sep 26, 2022 · 17 comments
Closed

Comments

@simogaspa84
Copy link

simogaspa84 commented Sep 26, 2022

Hi.. I created a web hosting account here..

https://systelfota.000webhostapp.com/

I am trying to update the fw after I have created the json file and uploaded with the .bin..

Running the example with https but not certificate I get
[E][HTTPClient.cpp:251] beginInternal(): failed to parse protocol

Can you tell me the meaning of this error ?

Thanks

#include <esp32fota.h>
#include <WiFi.h>

// Change to your WiFi credentials
const char *ssid = "";
const char *password = "";

// esp32fota esp32fota("<Type of Firme for this device>", <this version>, <validate signature>);
esp32FOTA esp32FOTA("esp32-fota-http", 1, false, true);

void setup_wifi()
{
  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

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

  Serial.println("");
  Serial.println(WiFi.localIP());
}

/**
 * @brief  Function to execute the setup generated by the arduino framework
 * @param  None
 * @retval None
 */
void setup(void)
{
  esp32FOTA.setManifestURL("https://systelfota.000webhostapp.com/fota.json");
  Serial.begin(115200);
  setup_wifi();
}
/**
 * @brief  Function to execute in loop generated by the arduino framework
 * @param  None
 * @retval None
 */
void loop(void)
{
  bool updatedNeeded = esp32FOTA.execHTTPcheck();
  if (updatedNeeded)
  {
    esp32FOTA.execOTA();
  }

  delay(2000);
}
@tobozo
Copy link
Collaborator

tobozo commented Sep 26, 2022

thanks for your report, looks like a bug in the library code

until this is fixed, one way to avoid the bug is to use a define or static variable to store the URL.

String my_manifest_url = "https://systelfota.000webhostapp.com/fota.json";

void setup(void)
{
  esp32FOTA.setManifestURL( my_manifest_url );
  Serial.begin(115200);
  setup_wifi();
}

@simogaspa84
Copy link
Author

simogaspa84 commented Sep 27, 2022

Thanks @tobozo for your suggestion.. I will try it now.. I am not sure that everything is set correctly So i put here the json ..

{
    "type": "esp32-fota-http",
    "version": "2",
    "url": "https://systelfota.000webhostapp.com/update.bin"
}

Can you check?

I don't know if the web hosting provider is set correctly..

I have tried now with your suggestion..

always the same..

[E][HTTPClient.cpp:251] beginInternal(): failed to parse protocol
[E][HTTPClient.cpp:251] beginInternal(): failed to parse protocol
// Change to your WiFi credentials
const char *ssid = "zzzzz";
const char *password = "xxxx";

String my_manifest_url = "https://systelfota.000webhostapp.com/fota.json";

// esp32fota esp32fota("<Type of Firme for this device>", <this version>, <validate signature>);
esp32FOTA esp32FOTA("esp32-fota-http", 1, false, true);

void setup_wifi()
{
  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

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

  Serial.println("");
  Serial.println(WiFi.localIP());
}

/**
 * @brief  Function to execute the setup generated by the arduino framework
 * @param  None
 * @retval None
 */
void setup(void)
{
  esp32FOTA.setManifestURL(my_manifest_url);
  Serial.begin(115200);
  setup_wifi();
}
/**
 * @brief  Function to execute in loop generated by the arduino framework
 * @param  None
 * @retval None
 */
void loop(void)
{
  bool updatedNeeded = esp32FOTA.execHTTPcheck();
  if (updatedNeeded)
  {
    esp32FOTA.execOTA();
  }

  delay(2000);
}

image

Thanks a lot

@simogaspa84
Copy link
Author

@tobozo please can you suggest a web hosting provider easy to configure to try all examples in your lib?
Thanks a lot

@tobozo
Copy link
Collaborator

tobozo commented Sep 27, 2022

@simogaspa84 your config looks good, can you try this sketch?

#include <esp32fota.h> // fota pulls WiFi library

const char *ssid = "zzzzz";
const char *password = "xxxx";

const char* firmware_name   = "esp32-fota-http";
const bool check_signature  = false;
const bool disable_security = true;

#define FOTA_URL "https://systelfota.000webhostapp.com/fota.json"

int firmware_version_major  = 2;
int firmware_version_minor  = 0;
int firmware_version_patch  = 0;

esp32FOTA FOTA; // empty constructor

void setup_wifi()
{
  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println(WiFi.localIP());
}

void setup(void)
{
  Serial.begin(115200);
  {
    auto cfg = FOTA.getConfig();
    cfg.name         = firmware_name;
    cfg.manifest_url = FOTA_URL;
    cfg.sem          = SemverClass( firmware_version_major, firmware_version_minor, firmware_version_patch );
    cfg.check_sig    = check_signature;
    cfg.unsafe       = disable_security;
    //cfg.root_ca      = MyRootCA;
    //cfg.pub_key      = MyRSAKey;
    FOTA.setConfig( cfg );
  }
  setup_wifi();
}

void loop(void)
{
  bool updatedNeeded = FOTA.execHTTPcheck();
  if (updatedNeeded)
  {
    FOTA.execOTA();
  }
  delay(2000);
}

@simogaspa84
Copy link
Author

hi @tobozo .. thanks for your code..

I have tried but it is failing

entry 0x400806a8 Connecting to Systel-Guest ..... 172.16.10.67 Error on HTTP request (httpCode=404) Error on HTTP request (httpCode=404) Error on HTTP request (httpCode=404) Error on HTTP request (httpCode=404) Error on HTTP request (httpCode=404) Error on HTTP request (httpCode=404) Error on HTTP request (httpCode=404) Error on HTTP request (httpCode=404)

@simogaspa84
Copy link
Author

simogaspa84 commented Sep 27, 2022

ok it was in the wrong location the json and the .bin file..
Moving them inside the right folder gives me

172.16.10.67
[E][WiFiClient.cpp:258] connect(): socket error on fd 55, errno: 113, "Software caused connection abort"
[E][WiFiClient.cpp:258] connect(): socket error on fd 57, errno: 113, "Software caused connection abort"
[E][WiFiClient.cpp:258] connect(): socket error on fd 59, errno: 113, "Software caused connection abort"
[E][WiFiClient.cpp:258] connect(): socket error on fd 61, errno: 113, "Software caused connection abort"
[E][WiFiClient.cpp:258] connect(): socket error on fd 63, errno: 113, "Software caused connection abort"
[E][WiFiClient.cpp:258] connect(): socket error on fd 55, errno: 113, "Software caused connection abort"

Any ideas @tobozo ?

@tobozo
Copy link
Collaborator

tobozo commented Sep 27, 2022

maybe give it a domain name instead of an IP address when calling HTTPS urls, or just use plain HTTP ? 😉

@simogaspa84
Copy link
Author

Sorry @tobozo .. I don't understand.. which is the mistake?
What should i do or change?
Thanks again

@simogaspa84
Copy link
Author

Hi @tobozo do i have to do something in the web hosting portal?
Can i keep the code in the same way?

Thanks a lot for your kind reply

@tobozo
Copy link
Collaborator

tobozo commented Sep 28, 2022

I don't know but 172.16.10.67 seems like a C class address (private) and those can't be routed on the internet, the domain name you specified earlier resolves to 145.14.145.212 and I don't see it in the logs, so maybe the failure is a consequence of that.

@simogaspa84
Copy link
Author

ok @tobozo so what do you suggest to do ?
Thanks

@tobozo
Copy link
Collaborator

tobozo commented Sep 28, 2022

I suggest you build more trust with yourself and stop relying on external assistance to disentangle local problems.
If you managed to get this far then you already have the skills to troubleshoot that, it's just a matter of not giving up :-)

@vortigont
Copy link

BTW, I've faced same issues. Looks like constructor with String object as input parameter turns into dangling pointer with const char * in cfg struct.
A suggested fix is to use const char overloads and pass String obj by reference - fix is included in PR #100

@tobozo
Copy link
Collaborator

tobozo commented Sep 29, 2022

indeed that was goofy, sorry about that 🙇

looking at your PR: I didn't know this notation, how does it compare to String blah=""; ?

    String UpdateURL((char *)0);
    String PartitionLabel((char *)0);

@vortigont
Copy link

String UpdateURL((char *)0);
this could be useful sometimes if you need a real empty String obj.

String blah=""; creates the obj with default ctor, than assigns a rvalue "" to it (which is const char*).
A default String preallocates some memory in advance (if that has not been changed recently).
And default c-tor for String is String(const char *cstr = ""); :))) So it's just unnecessary duplication, String blah; will end up with the same.

String UpdateURL((char *)0); creates String obj using c-tor with zero byte argument, so it ends up creating a really empty String in-place using move under the hood (as I remember it).

Mostly useful if combined with strobj.reserve() later to avoid extra mem allocation on object creation.

@simogaspa84
Copy link
Author

simogaspa84 commented Sep 30, 2022

thanks @tobozo and @vortigont . I will try the new commit asap

@tobozo
Copy link
Collaborator

tobozo commented Sep 30, 2022

@simogaspa84 there's a better implementation and more fixes from @vortigont on the 0.2.3 branch

@tobozo tobozo closed this as completed in a42c762 Sep 30, 2022
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

3 participants