SIM900 NTP query via UDP request - incomplete response via SoftwareSerial

Hi!
I'm currently working on a project with a SIM900 GSM module. To save power the module is usually unpowered and periodically is woken up via an RTC interrupt routine.

I would like to keep the RTC time synced via an NTP server and would like to fetch the current time stamp via an UDP request (unfortunately the standard SIM900 NTP AT queries are not working for my network).

Fetching the timestamp from an UDP server has already been done here and for the SIM900 library I use this one (this library has already some built-in functions for gprs connections and udp requests but for debug purposes I decided to send the AT commands manually).

I already managed it to make a connection and send the UDP packet, however there is a problem with getting the result string via the SoftwareSerial read function since I don't retrieve the full 48 word response string - it seems to stop receiving at the first '0x0' word of the UDP response.

In my code I'm able to send AT commands directly to the SIM900 via terminal - if I initiate sending the packet via terminal I get the full response.

Does someone has a clue on how to solve this issue and integrate a working read function in my code?
Thanks!

GPRS_NTPviaUDP.ino (2.63 KB)

terminal.txt (421 Bytes)

and periodically is woken up via an RTC interrupt routine.

So, you HAVE an RTC.

I would like to keep the RTC time synced via an NTP server

If your RTC drifts that much, spend an extra $ and get a better RTC. A DS3231 won't need to be synced but about once a year.

You SERIOUSLY need to investigate when Serial.write() is appropriate. You need to SERIOUSLY investigate just what write() takes as an argument and what read() returns. They are NOT the same thing.

What do you expect the Serial Monitor application, that expects you to send it text, to do when you send it binary data?

Specifically, what do you really expect it to do when you send it a NULL?

Your problem has NOTHING to do with SoftwareSerial. It is ALL about unrealistic expectations on your part.

Got it working after reading more about Serial Input Basics and changing the reading routine to a slightly modified version for receiving binary data in that post.

I'm attaching the sourcecode if someone tries something similar.

@PaulS:
I was trying to fetch the current time via an NTP server since I don't want to worry about setting the RTC manually when the unit is initially powered up.Turning on the GSM module and syncing the RTC with the NTP server at startup and every once and a while is basically for free.

GPRS_NTPviaUDP.ino (4.82 KB)