0

I want to parse a large number to sync time on my arduino. For this i send it a string with the current time in Unix time format wich looks somethink like this:

1535441277

For this I just call a php script wich echos thetime() function.

But withstring.toInt()I'm unable to parse it. I suppose the number is too large for an int or a long. But I can't put it directly into thesetEpoch() method from the RTCzero libary because it accepts as input datatype onlyuint32_t. So how can I parse large numbers on a system where double isn't implemented. And I don't just try to parse the entire HTTP-Response. I iterate thru the response and at the relevant line I write all the chars into a char-Array. I also have removed the \r and \n chars.

askedAug 28, 2018 at 7:37
Cowboy_Patrick's user avatar
0

2 Answers2

1

On 32 bit systems,uint32_t is usually the same asunsigned int andunsigned long. You should be able to parse the number usingstrtoul(), which is quite standard and returns anunsigned long.

answeredAug 28, 2018 at 7:48
Edgar Bonet's user avatar
0

Thanks for the quick response. I also found another solution: Before echoing the time remove a large chuck of the time by just removing the current timestamp on the server-side. Later on I add the exact same amount when using thesetEpoch() function. I know that's not very elegant but it works for me.

answeredAug 28, 2018 at 8:11
Cowboy_Patrick's user avatar
7
  • How do you share the time base (that large chunk) between the Arduino and the PC?CommentedAug 28, 2018 at 8:34
  • @DmitryGrigoryev, subtract epoch time of the first second of this yearCommentedAug 28, 2018 at 8:40
  • So you already have current time set on both Arduino and the PC?CommentedAug 28, 2018 at 8:48
  • @DmitryGrigoryev, read the question. he gets the time with HTTP GET request to his service on the serverCommentedAug 28, 2018 at 8:50
  • @Juraj I totally don't see that in the question.CommentedAug 28, 2018 at 8:57

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.