ARMmbed / ARMmbed/mbed-os-examples-docs_only

mbed-os-snippet-UDPSocket prints wrong time

Open Beginner friendly
#126 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5
Forks
26
PR merge metrics
No merged PRs in 30d

Description

The example shows the usage of an UDP socket, and this works. But finally, the received time (seconds sind 1970) prints the correct date only by sudden.
https://github.com/ARMmbed/mbed-os-snippet-UDPSocket/blob/18ae5c765b96ca5bcfd9c584c7cc776ff3ef0867/main.cpp#L48
There is a typecast from a 4 byte to an 8 byte pointer, this works only when the upper 4 bytes are zero.
This is a fix for this (PRs doesnt seem to be used):

```
time_t now = in_data.secs;
printf("Time = %s", ctime(&now));
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in main.cpp at the linked line 48 and inspect how the received seconds value is passed to ctime. Verify the timestamp conversion and run the UDP socket example to confirm that the printed date is consistently correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.