sockets - Arduino loose serial-connection with our server -


we trying develop webapplication receive data arduino. programmed arduino send (on web server) json's every 5 seconds. works fine 1-2 minutes don't receive data arduino. tx keeps blinking our console shows empty string. ideeas? ps. baudrate set 9600 if tell :)

here link code

according github issue page ajson library, seems there memory leak in print(ajsonobject *) function, returns buffer char array allocated malloc(), you're responsible calling free() on again. calling function print(ajsonobject *, ajsonstream *), calls printvalue , print(ajsonobject *), not keep references allocated array , consequently not free it.

it seems making ajson send data directly stream work if modify functions call print(ajsonobject *) free memory.

alternatively, can call print(ajsonobject *) yourself, send contents of char array out serial port, , free memory. easier modify many function calls in library itself.

edit: seems problem indeed, have tried code on mega2560 , printed out free memory after printing each json object (with of this library) , , got this:

{"value1":500,"value2":1000,"value3":1500,"value4":2000} freememory = 7755 {"value1":500,"value2":1000,"value3":1500,"value4":2000} freememory = 7644 <snip> {"value1":500,"value2":1000,"value3":1500,"value4":2000} freememory = 540 {"value1":500,"value2":1000,"value3":1500,"value4":2000} freememory = 429 {"value1":500,"value2":1000,"value3":1500,"value4":2000} freememory = 318 {"value1":500,"value2":1000,"value3":1500,"value4":2000} freememory = 207 {"value1":500,"":1000} freememory = 153  freememory = 153  freememory = 153  freememory = 153 

however, there 1 other thing have do, namely calling ajson.deleteitem() on json object, because contributes memory leak. try changing code in loop this:

ajsonobject *msg = createmessage(); char *json = ajson.print(msg); serial.print(json); serial.println(); free(json); ajson.deleteitem(msg); 

now, available memory stays same after each loop iteration:

{"value1":500,"value2":1000,"value3":1500,"value4":2000} freememory = 7884 {"value1":500,"value2":1000,"value3":1500,"value4":2000} freememory = 7884 {"value1":500,"value2":1000,"value3":1500,"value4":2000} freememory = 7884 <snip> 

edit 2: looks using stream works too, though still have call ajson.deleteitem(msg) after printing data.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -