Metasploit Graph and Append Array Difficulties

Hello,

So I an creating a graph to display ‘temp’ against ‘time’ reading data from a live temp module. I have created a brief example in notepad++ to confirm it works. I would like to display the temp curve over 60 minutes and append ‘channel_1_temp[]’ and ‘time_minutes_temp[]’ from the start of the test - so essentially the graph grows over time. Below are my notepad++ and the actually example from the live temp module.

The problem I am having with the ‘temp module example’, is the arrays don’t grow in size. They just stay at two elements. This is odd because the notepad++ example grew in size? Also looking at the below output, the ‘channel_1_temp [ 1 22]’ has a leading space at the start that seems to grow when left running?

Im sure I am missing something simple but I cannot see what I am doing wrong.

Many thanks,

Tuurbo46

Notepad++ example:

import numpy as np
import matplotlib.pyplot as plt

time_minutes = np.array([10, 20, 30, 40, 50]) # Minutes

temp_c = np.array([18, 20, 25, 25, 26])       # Celsius 

time_minutes = np.append(time_minutes, "60")  # add a time to the end of array
temp_c = np.append(temp_c, "30")              # add a temp to the end of array

        
plt.ylabel("C")
plt.xlabel("Minutes")

plt.plot(temp_c, time_minutes)
plt.show()

Temp module example called every 1 minute:

def temperature_graph():
    
    global time_minutes_temp
    global channel_1_temp
    global temp_chl_1
    global count
    
    count =+ 1 
        
    time_minutes_temp = np.array([1]) # Minutes
    
    channel_1_temp = np.array([1])    # Centigrade
    
    #---- Append time array by 1 minute ----
    time_minutes_temp = np.append(time_minutes_temp, [count]) 
 
    #---- Convert global temp float value to an int ----
    temp_chl_1_int = temp_chl_1   
    temp_chl_1_int = int(temp_chl_1_int)
    
    #---- Append temp array with latest temp value
    channel_1_temp = np.append(channel_1_temp, [temp_chl_1_int]) 
    
    print('time_minutes_temp', time_minutes_temp)
    
    print('channel_1_temp', channel_1_temp)
    
     
    plt.ylabel("C")
    plt.xlabel("Minutes")

    plt.plot(channel_1_temp, time_minutes_temp)
    plt.show()

Temp module output:

time_minutes_temp [1 1]

channel_1_temp [ 1 22]

time_minutes_temp [1 1]

channel_1_temp [ 1 22]

So that the graph grows over time, you can create a function such that you call it every time that you want to pass in new data and update the graph. In the following example, I have extended your data points to 10 and added a small delay for demo purposes. I added a for loop to simulate reading values from the user.

time_minutes = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
temp_c = [18, 20, 25, 25, 26, 24.5, 25, 25.3, 24.6, 24.6]

import matplotlib.pyplot as plt
import numpy as np

plt.ion()  # Turn interactive mode on
plt.xlabel('Time (minutes)')
plt.ylabel('Temperature (Celsius)')
plt.title('Time(min) vs. Temperature (C)')

# Create two lists that will save your data as it is being entered (passed in)
x, y = [], []
graph, = plt.plot(x, y)  # Notice the comma!
ax = plt.gca()

def update_data_graph(time, temp):

    # Generate new X and Y data
    x.append(time)
    y.append(temp)

    # Update data
    graph.set_data(x, y)

    # Rescale axes
    ax.relim()
    ax.autoscale_view()

    # Redraw and pause
    plt.draw()
    plt.pause(2)  # Add time delay between reading for simulation purposes only

# simulate calling function to update the graph
for i in range(len(time_minutes)):
    update_data_graph(time_minutes[i], temp_c[i])

input('Hit Enter to close graph.  ')

After it has completed running, the user is prompted to hit Enter to close the graph.