Question
Part 2 (Scenario 2) Note; When doing this homework, it should be done with C code. When doing this assignment, it should be done with
Part 2 (Scenario 2)
Note; When doing this homework, it should be done with C code. When doing this assignment, it should be done with C code, At the same time, the codes of assignment1 should be left below and have to use in this assignment. For this assignment we need to use Cooja Simulation on Docker.
Scenario 2 - Routing with RSSI Criteria 9 pieces of firmware named sayac.c and 1 piece of firmware named trafo.c are created. As shown in the figure below, node 10 (in the border-router role) is running trafo.c and the other nodes are running sayac.c. (Node number indices and order do not matter in this assignment. The distances between the nodes must be exactly the same as in the figure). RSSI-Received Signal Strength Indication stands for Received Signal Strength Indication.
For each node, the process of asking the RSSI information of its neighbors and choosing the maximum one among them is the most important part you need to code. For example, in Fig.3, node 1 has to find out the RSSI information of its neighbors before choosing between nodes 2 and 3, and then decide on node 3 as the father node. Since d is distance and d1-3
If "of" is coded correctly, the algorithm selects the nodes with high signal strength as the father nodes and the packets are transmitted through the selected father nodes while the packets are traveling from node 1 to node 10. As can be seen in Figure 3, the nodes on the green route 1-3-8-7-9-6-10 are closer to each other, so it is expected that nodes will prefer this route since the signal strength (RSSI) of the nodes closer to each other will be higher. Route 1-2-4-5-10 should not be preferred. With the RSSI routing criterion you defined, the simulation is run at the fastest speed (speed 1000x) for 2 minutes. In the elapsed time, the path marked in red should not be used at all.
If, while the simulation is running, when you hold the mouse on nodes 2 and 10 (blue arrow) as shown in Figure 4 and move it to the marked area, the packets now prefer the 1-2-10 path, then "of" is working correctly.
-------------------------------------------------------------------------------
Note: The firstnode.c code I used for the 1st assignment can be used for the sayac.c in this assignment.
firstnode.c
#include "contiki.h" #include "net/routing/routing.h" #include "netetstack.h" #include "net/ipv6/simple-udp.h" #include
#include "sys/log.h" #define LOG_MODULE "App" #define LOG_LEVEL LOG_LEVEL_INFO
#define WITH_SERVER_REPLY 1 #define UDP_CLIENT_PORT 8765 #define UDP_SERVER_PORT 5678
static struct simple_udp_connection udp_conn;
PROCESS(udp_server_process, "UDP server"); AUTOSTART_PROCESSES(&udp_server_process); /*---------------------------------------------------------------------------*/ static void udp_rx_callback(struct simple_udp_connection *c, const uip_ipaddr_t *sender_addr, uint16_t sender_port, const uip_ipaddr_t *receiver_addr, uint16_t receiver_port, const uint8_t *data, uint16_t datalen) { LOG_INFO("Received request '%.*s' from ", datalen, (char *) data); char control[] = "LIGHT6: TURNED_ON"; if(strcmp((char *)data,control) == 0){ LOG_INFO("LIGHT6 SUCCESSFULLY TURNED_ON "); } else{ LOG_INFO("LIGHT6 PROCESS FAILED "); } LOG_INFO_6ADDR(sender_addr); LOG_INFO_(" "); char resp[] = "LIGHT6: TURN_ON"; #if WITH_SERVER_REPLY /* send back the same string to the client as an echo reply */ LOG_INFO("Sending response. "); simple_udp_sendto(&udp_conn, resp, strlen(resp), sender_addr); #endif /* WITH_SERVER_REPLY */ } /*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_server_process, ev, data) { PROCESS_BEGIN();
/* Initialize DAG root */ NETSTACK_ROUTING.root_start();
/* Initialize UDP connection */ simple_udp_register(&udp_conn, UDP_SERVER_PORT, NULL, UDP_CLIENT_PORT, udp_rx_callback);
PROCESS_END(); } /*---------------------------------------------------------------------------*/
-------------------------------------------------------------------------------
Note: The sixthnode.c code I used for the 1st assignment can be used for the trafo.c in this assignment.
sxthnode.c
#include "contiki.h" #include "net/routing/routing.h" #include "random.h" #include "netetstack.h" #include "net/ipv6/simple-udp.h" #include
#include "sys/log.h" #define LOG_MODULE "App" #define LOG_LEVEL LOG_LEVEL_INFO
#define WITH_SERVER_REPLY 1 #define UDP_CLIENT_PORT 8765 #define UDP_SERVER_PORT 5678
#define SEND_INTERVAL (60 * CLOCK_SECOND)
static struct simple_udp_connection udp_conn; static uint32_t rx_count = 0; static uint32_t temp = 0; /*---------------------------------------------------------------------------*/ PROCESS(udp_client_process, "UDP client"); AUTOSTART_PROCESSES(&udp_client_process); /*---------------------------------------------------------------------------*/ static void udp_rx_callback(struct simple_udp_connection *c, const uip_ipaddr_t *sender_addr, uint16_t sender_port, const uip_ipaddr_t *receiver_addr, uint16_t receiver_port, const uint8_t *data, uint16_t datalen) { char control[] = "LIGHT6: TURN_ON"; if(strcmp((char *)data,control) == 0){ temp = 1 ; } else{ temp = 0; } LOG_INFO("Received response '%.*s' from ", datalen, (char *) data); LOG_INFO_6ADDR(sender_addr); #if LLSEC802154_CONF_ENABLED LOG_INFO_(" LLSEC LV:%d", uipbuf_get_attr(UIPBUF_ATTR_LLSEC_LEVEL)); #endif LOG_INFO_(" "); rx_count++; } /*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic_timer; static char str[32]; uip_ipaddr_t dest_ipaddr; static uint32_t tx_count; static uint32_t missed_tx_count; PROCESS_BEGIN();
/* Initialize UDP connection */ simple_udp_register(&udp_conn, UDP_CLIENT_PORT, NULL, UDP_SERVER_PORT, udp_rx_callback);
etimer_set(&periodic_timer, random_rand() % SEND_INTERVAL); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
if(NETSTACK_ROUTING.node_is_reachable() && NETSTACK_ROUTING.get_root_ipaddr(&dest_ipaddr)) {
/* Print statistics every 10th TX */ if(tx_count % 10 == 0) { LOG_INFO("Tx/Rx/MissedTx: %" PRIu32 "/%" PRIu32 "/%" PRIu32 " ", tx_count, rx_count, missed_tx_count); } if(temp == 1){ LOG_INFO_6ADDR(&dest_ipaddr); LOG_INFO_(" "); snprintf(str, sizeof(str), "LIGHT6: TURNED_ON"); simple_udp_sendto(&udp_conn, str, strlen(str), &dest_ipaddr); tx_count++; } else{ LOG_INFO_6ADDR(&dest_ipaddr); LOG_INFO_(" "); snprintf(str, sizeof(str), "WRONG REQ"); simple_udp_sendto(&udp_conn, str, strlen(str), &dest_ipaddr); tx_count++; } } else { LOG_INFO("Not reachable yet "); if(tx_count > 0) { missed_tx_count++; } }
/* Add some jitter */ etimer_set(&periodic_timer, SEND_INTERVAL - CLOCK_SECOND + (random_rand() % (2 * CLOCK_SECOND))); }
PROCESS_END(); } /*---------------------------------------------------------------------------*/
----------------------------------------------------------------------------------------------------------
Thanks
Figure.3 Routing with RSSI Criteria Fig.4 Routing Verification with RSSI Criteria
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started