@@ -53,13 +53,6 @@ def pymesh_init(self):
5353 # initialize Pymesh
5454 self .__pymesh = Pymesh (self .__pymesh_config , self .pymesh_new_message_cb )
5555
56- while not self .__pymesh .is_connected ():
57- print (self .__pymesh .status_str ())
58- time .sleep (3 )
59-
60- # send message to the Node having MAC address 5
61- self .__pymesh .send_mess (2 , "Hello World" )
62- print ("Done Pymesh init, forever loop, exit/stop with Ctrl+C multiple times" )
6356 self .__pymesh_br_enabled = False
6457
6558 if self .__pymesh_config .get ("br_ena" , False ):
@@ -69,8 +62,6 @@ def pymesh_init(self):
6962 print_debug (99 , "Set as border router" )
7063 self .__pymesh .br_set (PymeshConfig .BR_PRIORITY_NORM , self .pymesh_new_br_message_cb )
7164
72- self .__pybytes .send_signal (1 , str (self .__pymesh .mac ()) + " : " + str (time .time ()) + "s, " + str (pycom .get_free_heap ()))
73- print_debug (99 , "Send to Pyb," , pycom .get_free_heap ())
7465 else : # not connected anymore to pybytes
7566 if self .__pymesh_br_enabled :
7667 self .__pymesh_br_enabled = False
@@ -88,8 +79,13 @@ def unpack_pymesh_message(self, signal_number, value):
8879 pyb_ip = '1:2:3::' + hex (pyb_port )[2 :]
8980 pkt_start = self .__pack_tocken_prefix + self .__pack_tocken_sep + deviceID + self .__pack_tocken_sep
9081
91- self .__pymesh .send_mess_external (pyb_ip , pyb_port , pkt_start + monitoringData )
92- self .__pymesh .send_mess_external (pyb_ip , pyb_port , pkt_start + value )
82+ # send data to the port equal with signal_number
83+ self .__pymesh .send_mess_external (pyb_ip , signal_number , pkt_start + value )
84+
85+ time .sleep (3 ) # shouldn't send too fast to BR
86+
87+ # hardcode monitoring data to be sent on signal #2
88+ self .__pymesh .send_mess_external (pyb_ip , 2 , pkt_start + monitoringData )
9389
9490 def pymesh_new_message_cb (self , rcv_ip , rcv_port , rcv_data ):
9591 ''' callback triggered when a new packet arrived '''
@@ -122,9 +118,11 @@ def pymesh_new_br_message_cb(self, rcv_ip, rcv_port, rcv_data, dest_ip, dest_por
122118 if len (x ) > 2 :
123119 token = x [1 ]
124120 rcv_data = rcv_data [len (self .__pack_tocken_prefix ) + len (token ) + len (self .__pack_tocken_sep ):]
125- pkt = 'BR %d B from %s (%s), to %s ( %d): %s' % (len (rcv_data ), token , rcv_ip , dest_ip , dest_port , str (rcv_data ))
126- print_debug (99 , 'Pymesh node packet: {} ' .format (pkt ))
127- self .__pybytes .send_node_signal (1 , str (rcv_data .decode ()).replace ("#" , "" ), token .decode ())
121+
122+ # send data to Pybytes only if it's coded properly
123+ pkt = 'BR %d B from %s (%s), to %s ( %d): %s' % (len (rcv_data ), token , rcv_ip , dest_ip , dest_port , str (rcv_data ))
124+ print_debug (99 , 'Pymesh node packet: {} ' .format (pkt ))
125+ self .__pybytes .send_node_signal (dest_port & 0xFF , str (rcv_data .decode ()).replace ("#" , "" ), token .decode ())
128126 return
129127
130128 def get_config (self , token , silent = False ):
0 commit comments