Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Below is a short example of how an application can send a data struct every 5 seconds, followed by parsing any downstream data received since the last transmission.
 

 

Code Block
languagecpp
titleExample usage of QuickStart API
#include <stdlib.h>
#include "dn_qsl_api.h"

#define NETID           0       // Factory default value used if zero (1229)
#define JOINKEY         NULL    // Factory default value used if NULL (44 55 53 54 4E 45 54 57 4F 52 4B 53 52 4F 43 4B)
#define BANDWIDTH_MS    5000	// Not changed if zero (default base bandwidth given by manager is 9 s)
#define SRC_PORT		0		// Default port used if zero (0xf0b8)
#define DEST_PORT       0		// Default port used if zero (0xf0b8)

int main(void)
{
    my_data_struct_t myData;
    uint8_t bytesRead;
    uint8_t* myBuffer[DN_DEFAULT_PAYLOAD_SIZE_LIMIT];

    if (!dn_qsl_init())
    {
        return; // Initialization failed
    }

    while (TRUE)
	{
		if (dn_qsl_isConnected())
		{
			/*
			Prepare myData
			*/
			
			if (!dn_qsl_send(&myData, sizeof (myData), DEST_PORT))
			{
				// Pushing data to the manager failed
			}

			do
			{
				bytesRead = dn_qsl_read(inboxBuf);
				/*
				Parse received data
				*/
			} while (bytesRead > 0);
			
			/*
			Wait for next transmission (5000 ms)
			*/
		} else
		{
			if (dn_qsl_connect(netID, joinKey, srcPort, service_ms))
			{
				// Connected to network
			} else
			{
				// Failed to connect
			}
		}
	}

	return (EXIT_SUCCESS);
}

 

...