\section{SNTP client}

% Short description/overview of module functions
This module allows you to sync your device to to a specified (s)ntp server.
You can then retreive the time with the pico$\_$sntp$\_$gettimeofday function.


\subsection{pico$\_$sntp$\_$sync}

\subsubsection*{Description}
Function to sync the local time to a given sntp server.
\subsubsection*{Function prototype}
\begin{verbatim}
int pico_sntp_sync(char *sntp_server, void (*cb_synced)(pico_err_t status));
\end{verbatim}

\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{sntp$\_$server} - String with the sntp server to get the time from
\item \texttt{cb$\_$synced} - Callback function that is called when the synchronisation process is done. The status variable indicates wheter the synchronisation was succesfull or not.
\end{itemize}

\subsubsection*{Return value}
On success, this call returns 0 if the synchronisation operation has succeeded.
On error, -1 is returned and \texttt{pico$\_$err} is set appropriately.

\subsubsection*{Errors}
\begin{itemize}[noitemsep]
\item \texttt{PICO$\_$ERR$\_$EINVAL} - invalid argument
\item \texttt{PICO$\_$ERR$\_$ENOMEM} - not enough space
\end{itemize}

\subsubsection*{Example}
\begin{verbatim}
int ret = pico_sntp_sync("ntp.nasa.gov", &callback);
\end{verbatim}



\subsection{pico$\_$sntp$\_$gettimeofday}

\subsubsection*{Description}
Function to get the current time. Be sure to call the pico$\_$sntp$\_$sync function to synchronise BEFORE calling this function.

\subsubsection*{Function prototype}
\begin{verbatim}
int pico_sntp_gettimeofday(struct pico_timeval *tv);
\end{verbatim}

\subsubsection*{Parameters}
\begin{itemize}[noitemsep]
\item \texttt{tv} - Pointer to a time$\_$val struct in which the current time will be set.
\end{itemize}

\subsubsection*{Return value}
On success, this call returns 0 if the time is set.
On error, -1 is returned and \texttt{pico$\_$err} is set appropriately.

\subsubsection*{Example}
\begin{verbatim}
int ret = pico_sntp_gettimeofday(tv);
\end{verbatim}



