I'm setting up a home sensor network and I have multiple "nodes" (Arduino locations) and each node has several datapoints to report. So I'm storing all my nodes (node objects) in a list and each node object has a list of datapoint objects. My problem is that I can't seem to assign datapoints to individual nodes and they are instead assigned to all nodes in the node list.
class datapoint:
name = ""
node_number = 0
node_array_index = 0
active = False
log_next = False
def __init__(self, name):
self.name = name
class node:
address = [0]*8
name = " "
message_now = False
datapoints = []
def __init__(self, name ):
self.name = name
node_list = []
node_list.append(node("Garden"))
node_list.append(node("Kitchen"))
node_list[0].datapoints.append(datapoint("Humidity"))
node_list[1].datapoints.append(datapoint("Temperature"))
for i in range(0,len(node_list[1].datapoints)):
print(node_list[1].datapoints[i].name)
This returns
Humidity
Temperature
I would have expected this to return Temperature because only Temperature was assigned to node_list[1].datapoints. If I try creating objects first and appending them to the list I get the same result.
Thanks for any help.