BL40A2010 Introduction to IoT-Based Systems¶

Assignment 4, 19.09.2022¶

Author: Trieu Huynh Ba Nguyen¶

(1) Draw a graph with star topology with five nodes (one in the center $A$, four in the edges $B$-$E$). If the topology is directed as a many-to-one topology, write the structure of awareness of the system, considering that nodes $B$-$E$ acquire and process data about a supporting reality $T$, while $A$ can only receive data from it. Remember the notation $Xy$ means the image of $X$ by $Y$.

In [1]:
import networkx as nx #https://networkx.github.io/
import matplotlib.pyplot as plt #https://matplotlib.org/
import scipy as sp
import numpy as np

G = nx.star_graph(["A", "B", "C", "D", "E"])
nx.draw_networkx(G, node_color='black', font_color='white', edge_color='black', font_weight='bold',  node_size=700)
plt.axis('off')
plt.show()

(2) Assume that graph illustrate a scenario of four sensor nodes that also (pre-)process data and one aggregator node as follows. Nodes $B$ and $C$ monitor temperature and wind speed at Airport station in Lappeenranta, respectively. Nodes $D$ and $E$ monitor temperature and wind speed at Lepola station in Lappeenranta, respectively. Nodes $B$ and $D$ send a binary message to $A$ indicating if during that period the temperature was more than $25$ degrees ("1" means above, "0" means below or equal to). Likewise nodes $C$ and $E$ send a binary message to $A$ indicating if during that period the wind speed was more than $5$ m/s ("1" means above, "0" means below or equal to). Download and plot the data from FMI with 1 hour resolution during July, 2018. Using this data, plot the binary signals sent from the nodes $B$-$E$ to the aggregator $A$.

In [2]:
import pandas as pd 
import matplotlib.pyplot as plt 
import matplotlib.dates as mdates 
import numpy as np 

lentoasema_temp = pd.read_csv("LPR-lentoasema.csv",dayfirst=True,sep=",", 
                          header=0,decimal=b".",index_col=0,
                          parse_dates= [[0, 1, 2, 3]],usecols=[0,1,2,3,5])
lepola_temp = pd.read_csv("LPR-Lepola.csv",dayfirst=True,sep=",", 
                          header=0,decimal=b".",index_col=0,
                          parse_dates= [[0, 1, 2, 3]],usecols=[0,1,2,3,5])
lentoasema_wind = pd.read_csv("LPR-lentoasema.csv",dayfirst=True,sep=",", 
                          header=0,decimal=b".",index_col=0,
                          parse_dates= [[0, 1, 2, 3]],usecols=[0,1,2,3,6])
lepola_wind = pd.read_csv("LPR-Lepola.csv",dayfirst=True,sep=",", 
                          header=0,decimal=b".",index_col=0,
                          parse_dates= [[0, 1, 2, 3]],usecols=[0,1,2,3,6])

fig, ax1 = plt.subplots(figsize=(30,10))
ax1.set_ylabel("Temperature [°C]", color='black')
ax1.plot(lentoasema_temp>25,color='red', marker='o',linestyle='') 
ax1.plot(lepola_temp>25,color='blue', marker='o',linestyle='') 
ax2 = ax1.twinx() 
ax2.set_ylabel("Wing speed [m/s]", color='black',rotation=270,va="bottom")  
ax2.plot(lentoasema_wind>5,color='green', marker='x',linestyle='')
ax2.plot(lepola_wind>5,color='yellow', marker='x',linestyle='')
ax1.grid(True)
plt.title("Temperature and wind speed in July 2018")    
plt.show()

(3) Node $A$ needs to identify risky situations in Lappeenranta when the temperature is above $25$ degrees and the wind is above $5$ m/s based on the sensors' signals. If a risky situation is identified at node $A$ as binary number "1" while normal situations as "0". How would you solve this problem? Plot the output signal from node $A$ and discuss its relation to the input signals from $B$-$E$.

In [4]:
aux=((lentoasema_temp.values>25) & (lentoasema_wind.values>5)) | ((lepola_temp.values>25) & (lepola_wind.values>5))
#aux2=(Temperature2['2018-4-29'].values>7) | (ElectricityConsumption['2018-4-29'].values>0.2)
plt.figure(figsize=(16,6)) 
plt.plot(lepola_wind.index, aux,color='black', marker='o',linestyle='') 
plt.grid(True)
plt.title("Days with risky situations recorded at either station in Lappeenranta in July 2018")    
plt.show() 

Node A will result in $True$ if:

  1. Airport station records temperature above 25 degrees AND wind above 5 m/s OR
  2. Airport station records temperature above 25 degrees AND wind above 5 m/s