HTTP status code 504 means that your webserver got a timeout. This message might be caused because of a slow router/gateway of your service provider, but it is also possible that your embedded webserver reacts to slow for your phones (or vice versa, even though this is very unlikely).
You might want to try connecting with your phone(s) to your webserver using a wlan-connection instead of 3G to see if this problem consist.
Sort of EDIT:
You might consider implementing debugging output to your webserver. Also it could be useful to make the timeout-parameters configureable.
HTH,
flokra