Skip to content

Commit

Permalink
Merge pull request #338 from boyvinall/client-port
Browse files Browse the repository at this point in the history
awa_clientd and static API bind to random port
  • Loading branch information
cheekyhalf authored Feb 3, 2017
2 parents 28088bc + fc6ac7e commit b6c0a62
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 333 deletions.
2 changes: 1 addition & 1 deletion api/examples/tutorials/static-client-tutorial1.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(void)

AwaStaticClient_SetLogLevel(AwaLogLevel_Error);
AwaStaticClient_SetEndPointName(awaClient, "AwaStaticClient1");
AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 6000);
AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 0);
AwaStaticClient_SetBootstrapServerURI(awaClient, "coap://[127.0.0.1]:15685");

AwaStaticClient_Init(awaClient);
Expand Down
2 changes: 1 addition & 1 deletion api/examples/tutorials/static-client-tutorial2.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(void)

AwaStaticClient_SetLogLevel(AwaLogLevel_Error);
AwaStaticClient_SetEndPointName(awaClient, "AwaStaticClient1");
AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 6000);
AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 0);
AwaStaticClient_SetBootstrapServerURI(awaClient, "coap://[127.0.0.1]:15685");

AwaStaticClient_Init(awaClient);
Expand Down
2 changes: 1 addition & 1 deletion api/examples/tutorials/static-client-tutorial3.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int main(void)

AwaStaticClient_SetLogLevel(AwaLogLevel_Error);
AwaStaticClient_SetEndPointName(awaClient, "AwaStaticClient1");
AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 6000);
AwaStaticClient_SetCoAPListenAddressPort(awaClient, "0.0.0.0", 0);
AwaStaticClient_SetBootstrapServerURI(awaClient, "coap://[127.0.0.1]:15685");

AwaStaticClient_Init(awaClient);
Expand Down
7 changes: 7 additions & 0 deletions core/src/client/lwm2m_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>

#include "awa/static.h"
#include "lwm2m_security_object.h"
Expand Down Expand Up @@ -99,6 +101,11 @@ AwaError AwaStaticClient_Init(AwaStaticClient * client)
{
if (client->CoAPConfigured && client->BootstrapConfigured && client->EndpointNameConfigured)
{
if (client->CoAPListenPort == 0)
{
srand(time(NULL));
client->CoAPListenPort = 6000 + (rand() % 32768);
}
client->CoAPInfo = coap_Init(client->CoAPListenAddress, client->CoAPListenPort, false, Lwm2m_GetLogLevel());

if (client->CoAPInfo != NULL)
Expand Down
Loading

0 comments on commit b6c0a62

Please sign in to comment.