Skip to content

Commit 209525e

Browse files
author
Maksymilian Wojczuk
committed
Wakaama
Fixed registration on server
1 parent 621c848 commit 209525e

File tree

7 files changed

+54
-56
lines changed

7 files changed

+54
-56
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ WAKAAMA_INC = \
208208

209209
WAKAAMA_SYMBOL = -DLWM2M_LITTLE_ENDIAN
210210
WAKAAMA_SYMBOL += -DLWM2M_CLIENT_MODE
211-
WAKAAMA_SYMBOL += -DLWM2M_MEMORY_TRACE
211+
#WAKAAMA_SYMBOL += -DLWM2M_MEMORY_TRACE
212212
#WAKAAMA_SYMBOL += -DCOAPLOG # download logs
213213
#WAKAAMA_SYMBOL += -DLWM2M_WITH_LOGS # LOGS
214214

Middlewares/Third_Party/wakaama/client/client_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
#define DEVICE_NAME "Remote Programmer"
66

7-
#define SERVER_URI "coap://192.168.1.13:5683"
7+
#define SERVER_URI "coap://192.168.2.1:5683"
88
#define LWM2M_PORT 5683
99
#define MAX_PACKET_SIZE 1024
1010

1111
#define WAKAAMA_SHORT_ID 100 // 0 is forbidden
12-
#define WAKAAMA_BINDING 'U'
12+
#define WAKAAMA_BINDING "U"
1313
#define WAKAAMA_COMPANY 'AGH'
1414
#define WAKAAMA_MODEL_NUMBER DEVICE_NAME
1515

Middlewares/Third_Party/wakaama/client/objects/object_device.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,9 @@ lwm2m_object_t * get_object_device()
246246
*/
247247
lwm2m_object_t * deviceObj;
248248

249-
printf("ALLOC\n\r");
250249
deviceObj = (lwm2m_object_t *)lwm2m_malloc(sizeof(lwm2m_object_t));
251-
printf("Alloced!\n\r");
252250
if (NULL != deviceObj)
253251
{
254-
printf("NULL\n\r");
255252
memset(deviceObj, 0, sizeof(lwm2m_object_t));
256253

257254
/*
@@ -285,7 +282,6 @@ lwm2m_object_t * get_object_device()
285282
deviceObj->discoverFunc = prv_device_discover;
286283

287284
}
288-
printf("GO on!\n\r");
289285

290286
return deviceObj;
291287
}

Middlewares/Third_Party/wakaama/client/objects/object_security.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ lwm2m_object_t * get_security_object()
215215
targetP->instanceId = 0;
216216
targetP->uri = SERVER_URI;
217217
targetP->isBootstrap = false;
218-
targetP->shortID = 123;
218+
targetP->shortID = WAKAAMA_SHORT_ID;
219219
targetP->clientHoldOffTime = 10;
220220

221221
securityObj->instanceList = LWM2M_LIST_ADD(securityObj->instanceList, targetP);

Middlewares/Third_Party/wakaama/platform/platform.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@
1717
#ifdef LWM2M_MEMORY_TRACE
1818
void * lwm2m_trace_malloc(size_t s, const char * file, const char * function, int lineno) {
1919
printf("lwm2m_malloc: \"%s\" : \"%s\" : %d \n", file, function, lineno);
20-
return pvPortMalloc(s);
20+
return mem_malloc(s);
2121
}
2222
#else
2323
void * lwm2m_malloc(size_t s){
24-
return pvPortMalloc(s);
24+
return mem_malloc(s);
2525
}
2626
#endif
2727

2828
// Deallocate a block of memory previously allocated by lwm2m_malloc() or lwm2m_strdup()
2929
#ifdef LWM2M_MEMORY_TRACE
3030
void lwm2m_trace_free(void * p, const char * file, const char * function, int lineno) {
3131
printf("lwm2m_free: \"%s\" : \"%s\" : %d \n", file, function, lineno);
32-
return vPortFree(p);
32+
mem_free(p);
3333
}
3434
#else
3535
void lwm2m_free(void * p) {
36-
return vPortFree(p);
36+
mem_free(p);
3737
}
3838
#endif
3939

Src/lwip.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ void MX_LWIP_Init(void)
110110
dhcp_start(&gnetif);
111111

112112
/* USER CODE BEGIN 3 */
113-
114113
/* USER CODE END 3 */
115114
}
116115

Src/main.c

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@
5555
#include "usb_host.h"
5656

5757
/* USER CODE BEGIN Includes */
58-
#include "term_io.h"
5958
#include "debug_leds.h"
60-
#include "liblwm2m.h"
61-
#include "sockets.h"
6259
#include "connection.h"
6360
#include "objects.h"
6461
#include "client_config.h"
@@ -363,7 +360,6 @@ static void taskWakaama(void *socket) {
363360
int result;
364361
while(1){
365362

366-
//vTaskDelay(1000); // TODO
367363
printf("wakaama has started!\n");
368364
result = 1;
369365

@@ -392,7 +388,6 @@ static void taskWakaama(void *socket) {
392388
continue;
393389
}
394390
printf("ServerObject Created\n\r");
395-
printf("NEXT printf\n\r");
396391

397392
if(objArray[2] == NULL) {
398393
printf("Getting object device\n\r");
@@ -427,13 +422,13 @@ static void taskWakaama(void *socket) {
427422
* the number of objects we will be passing through and the objects array
428423
*/
429424
result = lwm2m_configure(lwm2mContext, DEVICE_NAME, NULL, NULL, OBJ_COUNT, objArray);
430-
if (result != 0) {
431-
printf(stderr, "lwm2m_configure() failed: 0x%X\r\n", result);
425+
if (result != COAP_NO_ERROR) {
426+
printf("lwm2m_configure() failed: 0x%X\r\n", result);
432427
result = -9;
433428
}
434429

435430
printf("LWM2M Client has started\n");
436-
431+
print_state(lwm2mContext);
437432
while (q_reset == 0) {
438433
struct timeval tv;
439434
fd_set readfds;
@@ -642,46 +637,54 @@ void StartDefaultTask(void const * argument)
642637

643638
/* USER CODE BEGIN 5 */
644639
printf("\n\n\n-----------------------START-------------------------\n\n");
645-
640+
osDelay(3000); // wait for DHCP initialisation
646641
// Initialize Wakaama LWM2M Client
642+
lwip_socket_init();
647643
int socket = getUDPSocket(LWM2M_PORT, AF_INET);
648-
if(socket != -1){
649-
int res = xTaskCreate(taskWakaama, "wakaama", 10000, (void *) socket, 2, NULL);
650-
if (res != pdPASS) {
651-
printf("\r\ntaskWakaama xTaskCreate returned %d\n", res);
652-
}
653-
644+
if(socket != -1){
645+
printf("Start wakaama\r\n");
646+
int res = xTaskCreate(taskWakaama, "wakaama", 3000, (void *) socket, 2, NULL);
647+
if (res != pdPASS) {
648+
printf("\r\nerror creating taskWakaama: xTaskCreate returned %d\n", res);
654649
}
650+
} else {
651+
printf("Error creating socket: ");
652+
}
655653

656-
657-
int x = 0;
658-
osDelay(500);
659-
HAL_GPIO_WritePin(USB_GPIO_OUT_GPIO_Port, USB_GPIO_OUT_Pin, GPIO_PIN_SET);
660-
BlinkBlue();
661-
char usrInput[2];
662-
/* Infinite loop */
663-
debug_init(&huart3);
664-
for(;;)
665-
{
666-
printf("in loop %d\n\r", x);
667-
x++;
668-
printf("$ ");
669-
fflush(stdout);
670-
get_line(usrInput, 2);
671-
printf("%s\n", usrInput);
672-
switch(usrInput[0]) {
673-
case 'l':
674-
if (get_usb_ready()) {
675-
usb_ls();
676-
}
677-
break;
678-
case 'w':
679-
if (get_usb_ready()) {
680-
usb_write("asd", 3);
681-
}
682-
break;
683-
}
654+
while(1) {
655+
osDelay(500);
684656
}
657+
658+
// TODO: We cannot wait actively for user input since it kills the connection
659+
// int x = 0;
660+
// osDelay(500);
661+
// HAL_GPIO_WritePin(USB_GPIO_OUT_GPIO_Port, USB_GPIO_OUT_Pin, GPIO_PIN_SET);
662+
// BlinkBlue();
663+
// char usrInput[2];
664+
// /* Infinite loop */
665+
// debug_init(&huart3);
666+
// for(;;)
667+
// {
668+
// osDelay(5);
669+
// printf("in loop %d\n\r", x);
670+
// x++;
671+
// printf("$ ");
672+
// fflush(stdout);
673+
// get_line(usrInput, 2);
674+
// printf("%s\n", usrInput);
675+
// switch(usrInput[0]) {
676+
// case 'l':
677+
// if (get_usb_ready()) {
678+
// usb_ls();
679+
// }
680+
// break;
681+
// case 'w':
682+
// if (get_usb_ready()) {
683+
// usb_write("asd", 3);
684+
// }
685+
// break;
686+
// }
687+
// }
685688
/* USER CODE END 5 */
686689
}
687690

0 commit comments

Comments
 (0)