1 #include "../src/logger.h"
2 #include "../src/system.h"
3 #include "../src/meshlink.h"
5 static 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 const char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/";
13 const char *name = argc > 2 ? argv[2] : "foo";
14 const char *remotename = argc > 3 ? argv[3] : "bar";
16 meshlink_handle_t *myhandle;
18 myhandle = meshlink_open(confbase, name, "meshlinkapp", DEV_CLASS_STATIONARY);
21 fprintf(stderr, "Could not open MeshLink: %s", meshlink_strerror(meshlink_errno));
25 //Register callback function for incoming data
26 meshlink_set_receive_cb(myhandle, (meshlink_receive_cb_t)handle_recv_data);
28 if(!meshlink_start(myhandle)) {
29 fprintf(stderr, "Could not start MeshLink: %s", meshlink_strerror(meshlink_errno));
36 meshlink_node_t *remotenode = meshlink_get_node(myhandle, remotename);
39 fprintf(stderr, "Node %s not known yet.\n", remotename);
43 //sample data to send out
45 memset(mydata, 0, 200);
46 strcpy(mydata, "Hello World!");
49 if(!meshlink_send(myhandle, remotenode, mydata, sizeof(mydata))) {
50 fprintf(stderr, "Error sending data: %s", meshlink_strerror(meshlink_errno));
55 meshlink_stop(myhandle);
56 meshlink_close(myhandle);