EtherCard icon indicating copy to clipboard operation
EtherCard copied to clipboard

PROGMEM declared makes it impossible to dynamically assign website

Open jatayu86 opened this issue 7 years ago • 8 comments

Hi,

The website is currently declared as const char* website[] PROGMEM which is essential for the library to work.My application needs to dynamically change website to implement a fall back server functionality.How can this be done?

jatayu86 avatar Apr 07 '17 05:04 jatayu86

Hello @jatayu86 ,

It does not need to be const. You can use char*. Just use fromRam=true in the ether.dnsLookup function so it knows that the string is in ram and not in PROGMEM. For instance (if you need to dynamically change to some pre-defined addresses):

char website1[] = "github.com";
char website2[] = "google.com";

char* website = website1;
if (!ether.dnsLookup(website, true))
    Serial.println("DNS failed");
ether.printIp("Server: ", ether.hisip);

website = website2;
if (!ether.dnsLookup(website, true))
    Serial.println("DNS failed");
ether.printIp("Server: ", ether.hisip);

The above is not tested, but it should work.

nuno-silva avatar Apr 07 '17 08:04 nuno-silva

I tried with your suggestion, dnslookup succeded,however the browseurl fails. It doesn't seem to be firing the right url.Also entire code has a weird behavior ,in the sense some other character arrays which i am printing in console doesnt show the correct data that i declared.Any suggestions would be helpful :)

Code: char website1[] = "xxx.com"; char *website=website1; if (!ether.dnsLookup(website,true)) Serial.println("DNS failed"); ether.printIp("SRV: ", ether.hisip); }

ether.browseUrl(PSTR("/dat?ins=xxx"), NULL, website, my_callback);

Output: <<< REQ >>> HTTP/1.1 302 Found Date: Fri, 07 Apr 2017 10:20:16 GMT Server: Apache/2.2.15 (Red Hat) Location: https://$S/dat?ins=xxx Content-Length: 301 Connection: close Content-Type: text/html; charset=iso-8859-1

jatayu86 avatar Apr 07 '17 10:04 jatayu86

It seems that the ether.browseUrl functions expects the hoststr (website) to be in program memory:

ether.browseUrl uses www_client_internal_datafill_cb to make the request, which uses BufferFiller::emit_p(const char* fmt PROGMEM, ...), which expects strings to be in program memory. Unfortunately I don't think there's a workaround for that.

nuno-silva avatar Apr 07 '17 11:04 nuno-silva

Is there any solution yet??? I need to change website address dynamically as well

GonzoAS avatar Jan 30 '20 18:01 GonzoAS

Is there any solution yet??? I need to change website address dynamically as well Maybe you know this but i'd declare a variable with PROGMEM and around 100 bytes length, then i'd fill with string that i'd want. it sucks but it would work

leanmendoza avatar Feb 01 '20 15:02 leanmendoza

I am not sure if you can assign a variable to a progmem and make it work with this library.What i had done is assign two seperate progmem with static url's and call them individually inside a conditional statement.Of course this works only if your requirement demands switiching of urls(domain names) based on certain conditions.Also not an efficient solution :).

On Sat, 1 Feb, 2020, 20:41 leamendoza97, [email protected] wrote:

Is there any solution yet??? I need to change website address dynamically as well Maybe you know this but i'd declare a variable with PROGMEM and around 100 bytes length, then i'd fill with string that i'd want. it sucks but it would work

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/njh/EtherCard/issues/268?email_source=notifications&email_token=AC4P3345LXNGSMFGWPDGLX3RAWGJ7A5CNFSM4DGZ4KB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKQ7HLY#issuecomment-581039023, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4P33ZKU7TFGWWP3R3TE7TRAWGJ7ANCNFSM4DGZ4KBQ .

jatayu86 avatar Feb 01 '20 15:02 jatayu86

SOLVED! a tiny cracked solution but it works.

const char website[] PROGMEM = "";

char hisipSD[] // char array with dinamic ip, i only had to concatenate website and hisipSD, has some warnings but it works!

ether.browseUrl(PSTR("/iBreader?"), str, strcat(website,hisipSD), my_callback);

GonzoAS avatar Feb 04 '20 17:02 GonzoAS

I am not sure if you can assign a variable to a progmem and make it work with this library.What i had done is assign two seperate progmem with static url's and call them individually inside a conditional statement.Of course this works only if your requirement demands switiching of urls(domain names) based on certain conditions.Also not an efficient solution :). On Sat, 1 Feb, 2020, 20:41 leamendoza97, @.***> wrote: Is there any solution yet??? I need to change website address dynamically as well Maybe you know this but i'd declare a variable with PROGMEM and around 100 bytes length, then i'd fill with string that i'd want. it sucks but it would work — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#268?email_source=notifications&email_token=AC4P3345LXNGSMFGWPDGLX3RAWGJ7A5CNFSM4DGZ4KB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKQ7HLY#issuecomment-581039023>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4P33ZKU7TFGWWP3R3TE7TRAWGJ7ANCNFSM4DGZ4KBQ .

hi any opinion about what i did?

GonzoAS avatar Feb 12 '20 20:02 GonzoAS