Advice on reading numbers from website

Hi,

I'm after a bit of advice on the best way of returning a signed integer from my webpage and parsing it in the arduino code.

I already have the ethernet library accessing my page and I can read the response I really just need advice on what the best practice is for communicating this way.

Also, as an aside - Im finding that when I update my sketches, the client wont connect unless I give it a different IP to the last time, can anyone advise me as to what might be causing it? I have a workaround but I don't really want to have to keep changing IP.

Thanks

Hello,

Is there a reason you don't want to provide the data in a binary form?

  • Brian

Since the integer in the web page is a string, a call to atoi() function would transform it into the integer type.

Also, as an aside - Im finding that when I update my sketches, the client wont connect unless I give it a different IP to the last time, can anyone advise me as to what might be causing it? I have a workaround but I don't really want to have to keep changing IP.

Sounds like you might be running into the known issue of the source port not being incremented properly. Have a look at a few of the active Ethernet threads on the forums some of which include updated code.

--Phil.

Is there a reason you don't want to provide the data in a binary form?

No... just that it's not something I'm used to doing. I'm a perl programmer and so tend to think in strings...

Do you have a simple example of how that would look? Or a link to somewhere with the right info?

Do you have a simple example of how that would look?

Unfortunately I don't. I am willing to do whay I can to help you get it working.

Or a link to somewhere with the right info?

I can't provide that either.

No... just that it's not something I'm used to doing. I'm a perl programmer and so tend to think in strings

In that case, is there a reason you'd like to transfer the data in a binary form?

  • Brian

In that case, is there a reason you'd like to transfer the data in a binary form?

I don't really mind how I transfer it. The site I'm reading from is mine and has no need to be readable by anything other than the arduino.

The fact that reading in a number isn't completely trivial makes me think that there must be an alternative that I'm missing. I don't know if that's binary, something else, or whether I'm just lazy cause I'm not used to having to handle this stuff myself!

Sounds like you might be running into the known issue of the source port not being incremented properly. Have a look at a few of the active Ethernet threads on the forums some of which include updated code.

Thanks for the pointer - I've had a look around. I have a recent download of the Arduino code so some of the fixes were already in. I also tried downloading a patched version that someone had put up recently but I'm still having the same problem. I can make as many connections as I want on a particular IP by resetting the device but if I upload the same sketch again without changing the IP I just get connection failed. I'm at a complete loss as to how to sort this out.

Is it something that depends on the configuration of the host? I don't have the same problem if I use google as the target server.

I don't really mind how I transfer it.

It that case, go with what is most comfortable for you. From what you've described, text is the best choice.

Some advantages...

  • It's human readable. You will be able to access the web page and read the number yourself. If the Arduino behaves the way you expect for that value, it's very likely that everything is working.

  • It can be expanded. If you need to pass two numbers, send them with a separator like CR-LF.

  • You needn't be concerned with endianness (byte ordering).

The only disadvantage is performance. The web server has to convert the value to text and the Arduino has to convert it back to a binary form.

The amount of data transferred is so small in either case it isn't really worth considering.

One potential caveat is the atoi function. Some implementations will not tolerate trailing characters (like a CR-LF). Some will not tolerate leading spaces. You may have to trim the number before calling atoi.

Have I confused you more or does that help?

  • Brian

That's great thanks. I think I'll use the string to start with although I'd like to learn to use the most efficient method eventually. I'm afraid I'm rather crippled atm by the weird problems connecting to my host but I look forward to using your advice when I solve that issue!