Digistump Forums

The DigiX => DigiX Libraries => Topic started by: jamiecockrill on July 15, 2014, 12:19:05 pm

Title: DigiFi optimisation
Post by: jamiecockrill on July 15, 2014, 12:19:05 pm
Hello all,

I've forked DigiFi to resolve some issues I was having in the following post in the support forum:

http://digistump.com/board/index.php/topic,1475.0.html

I was having issues with using DigiFi in client mode. I was regularly getting "400 - Bad Request" messages in my web-server logs and when I ran a packet-capture I found quite a lot of the AT commands leaking into my requests (see my support post for the long boring detail).

In the following commit (https://github.com/jdcockrill/DigiFi/commit/5e5909258925f2c1813e00300f8922850b9e059a) I made a number of changes that might want to be incorporated into the main library:

Usage of startATMode, get and post is just the same as before. Only difference is that get and post now return an int.

There are lots of things to do and some of those TODO's are listed in the code. However it'd be good to:

I'm happy to contribute to some of this stuff. Would it be preferable if I created 'issues' in github and pushed commits against those on my fork? I've no idea how pull requests work.
Title: Re: DigiFi optimisation
Post by: jamiecockrill on July 15, 2014, 12:43:33 pm
PS I didn't make it entirely clear, but these modifications seem to have fixed the issues I was seeing previously.

Before I'd get a few minutes before starting to get errors, then after a couple of hours I would stop seeing requests. Now its been going to 3 days and seems pretty resilient to the server going up and down when I turn it off for a few hours.
Title: Re: DigiFi optimisation
Post by: digistump on July 17, 2014, 05:17:06 pm
please open issues and send the pull requests - that would be awesome!

Thanks this looks like great changes!
Title: Re: DigiFi optimisation
Post by: jamiecockrill on July 18, 2014, 02:42:52 pm
All done - no problem.

Added a couple more things in there as well. I was finding that the part which checks the content length and skips retrieving the Body if "Content-Length: 0" wasn't working properly. I don't know if it was expecting to compare a char against a String or something, but I've replaced it with a straight integer comparison and it works fine now.

I've also added a timeout to readResponse as I found that I could, if I tried a few times, send the DigiX into an infinite loop by restarting apache (or whatever web server it was reading data from) whilst it was in the readResponse method as it would get stuck in a scenario where it hadn't reached the end, but Serial is suddenly unavailable. I've just put the standard 15s timeout into the method (uses the timeout number in the header file).

It still needs the Serial port to go unavailable to hit the break in the loop, so If someone has a constant stream of data flowing for longer than 15s, they would be unaffected. Its only if your Serial connection flicks between available and unavailable that it might need to be extended.