I'm trying to build a MQTT-SN with a MQTT-Rime gateway. I succeed to send sensor data to the gateway with a serial socket but my gateway have to send some data too to the motes. My problem is that I don't know how to read data from the socket in a mote. Someone can help me?
1 Answers
0
votes
If the input data is newline-terminated ASCII, you can use the serial line interface.
#include "contiki.h"
#include "dev/serial-line.h"
#include <stdio.h>
PROCESS(test_serial, "Serial line test process");
AUTOSTART_PROCESSES(&test_serial);
PROCESS_THREAD(test_serial, ev, data)
{
PROCESS_BEGIN();
for(;;) {
PROCESS_YIELD();
if(ev == serial_line_event_message) {
printf("received line: %s\n", (char *)data);
}
}
PROCESS_END();
}
If the data is binary, you need define your own callback function:
int binary_input_byte(unsigned char c) {
// ...
}
Then set this as the serial interface callback (using uart0 here, the exact name you need to use is platform-dependent):
uart0_set_input(binary_input_byte);