1 #include "../src/logger.h"
2 #include "../src/system.h"
3 #include "../src/meshlink.h"
5 void handle_recv_data(meshlink_handle_t *mesh, meshlink_node_t *source, void *data, size_t len) {
8 printf("Received %zu bytes from %s: %s\n", len, source->name, (char *)data);
11 int main(int argc, char **argv) {
12 char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/";
13 char *name = argc > 2 ? argv[2] : "foo";
15 char *remotename = argc > 3 ? argv[3] : "bar";
17 meshlink_handle_t *myhandle;
19 myhandle = meshlink_open(confbase, name, "meshlinkapp", DEV_CLASS_STATIONARY);
21 //Register callback function for incoming data
22 meshlink_set_receive_cb(myhandle, (meshlink_receive_cb_t)handle_recv_data);
24 meshlink_start(myhandle);
29 meshlink_node_t *remotenode = meshlink_get_node(myhandle, remotename);
32 fprintf(stderr, "Node %s not known yet.\n", remotename);
36 //sample data to send out
38 memset(mydata, 0, 200);
39 strcpy(mydata, "Hello World!");
42 meshlink_send(myhandle, remotenode, mydata, sizeof(mydata));
45 meshlink_stop(myhandle);
46 meshlink_close(myhandle);