Project

General

Profile

Ethercard: Fixed and configurable server IP address (No DNS) and browseurl problem

Added by farrenh about 4 years ago

Hi there,

I’m a C# programmer with a limited grasp of C+. I have a jeenode connected to an ethercard via the carrier board and am having trouble getting the web client on the Jeenode to work the way I want it to, using the Ethercard library.
1. The server I’m connecting to is on a local network, has a fixed IP and a custom port and I don’t want to use DNS. The server is an embedded server that I wrote inside a c# program that does a lot of other stuff, not a standard web server like IIS or Apache. It’s tested and working, both from a simple (but missing required functionality - see below) web client on the Jeenode and from a browser on another machine.
2. I’m developing a product that will be deployed at multiple sites, so when I say “fixed IP” I mean it’s a fixed IP for any given deployment, NOT that the server IP will be the same for all deployments. Again, I don’t want to use a DNS server to solve this, for a variety of reasons. I want a configurable fixed IP address for the server - the server IP cannot be hard-coded in the jeenode code.
3. I already have code that works that allows you to plug the jeenode into the server via USB and provide configuration information, including Encryption key (for RF) and the fixed server IP address it must use for web requests, which are all then stored in EEPROM. This is all tested and working.
4. In my ethernet setup I read the server IP from the EEPROM and modify hisip like this
<pre>
uint8_t serverAddress[4]={0};
uint16_t serverPort=2048;

for (int i =0;i<4;i)
serverAddress[i]=(uint8_t)EEPROM.read((int)RF12_EEPROM_SERVERIP+i);
ether.hisip[0]=serverAddress[0];
ether.hisip[1]=serverAddress[1];
ether.hisip[2]=serverAddress[2];
ether.hisip[3]=serverAddress[3];
ether.hisport=serverPort;
</pre>
5. But when I get here
<pre>
ether.browseUrl(PSTR ("/"), “?param1=1&param2=2”, “This is a &
^&&* problem for me”, webCallback);
</pre>
every single related post I could find on the web wants me to put a PSTR (literal) where I have swears above (the hoststr parameter). If I hard code the IP address I’m using for development, like this
<pre>
ether.browseUrl(PSTR ("/"), “?param1=1&param2=2”, PSTR ("10.0.0.2"), webCallback);
</pre>
it all works perfectly. I get the properly formed requests on my embedded HTTP server and the jeenode correctly reports what it got back via serial.prints.
But as stated above this is a problem. What I want to put in the place of PSTR (“10.0.0.2”) is the server address I got from the EEPROM. i.e. serverAddress[]. I have tried converting it to a string, converting the string to a const char*, but no matter what I try
ether.browseUrl(PSTR ("/"), “?param1=1&param2=2”, serverIPstring.c_str(), webCallback)//serverIPstring from prior conversion code String
or
ether.browseUrl(PSTR ("/"), “?param1=1&param2=2”, serverIPchar, webCallback) //serverIPchar from prior conversion code to const char*
or half a dozen other attempted solutions
nothing works. Having dug down into the c libraries a bit and read various posts with a limited understanding of c, I get the impression the code was written in such a way that the troublesome param is a constant in program memory which cannot be dynamically altered. Am I basically screwed? Do I have to re-write a lot of C
+ code in the libraries (which I’m loathe to do)? Or is there some easy hack to make it work the way I want it to?

[edit]

I’m using VisualMicro (http://www.visualmicro.com/) with Visual Studio, not the standard Arduino IDE, to compile and upload, if that is relevnt


Replies (1)

RE: Ethercard: Fixed and configurable server IP address (No DNS) and browseurl problem - Added by farrenh about 4 years ago

Realizing the extra array is just bloat I refactored down to

for (int i =0;i<4;i++)
         ether.hisip[ 0 ]=(uint8_t)EEPROM.read((int)RF12_EEPROM_SERVERIP+i);

but otherwise my problem remains the same

    (1-1/1)