1
from microbit import *
import radio

radio.on()  
radio.config(channel=8)
routing_table = { 'Alice': 8, 'Bob': 10, 'Charlie': 15 }
spy = 60

def forward_message(msg):
    source, destination, payload = msg.split(':')
    radio.config(channel=10)
    radio.send(msg)

def forward_to_spy(msg):
    source, destination, payload = msg.split(':')
    radio.config(channel=60)
    radio.send(msg)

while True:
    msg = radio.receive()
    if msg:
        msg = radio.receive()
        forward_message(msg)
        forward_to_spy(msg)
        ack = radio.receive()
        while ack is None:
            ack = radio.receive()
        forward_message(ack)

Whenever I submit this code it comes up with that error, could someone please help me. I am trying to receive messages and then send them to who they need to go to but also sending the message to a spy for a course in grok. I have been stuck on this for ages now so again please can someone please help.

Timus
  • 10,974
  • 5
  • 14
  • 28
Muhammad MOAZ
  • 11
  • 1
  • 3

1 Answers1

1

You are checking for the message, but then receiving another message on the next line and not checking if it's None.

  msg = radio.receive()
  if msg:
    msg = radio.receive()
    forward_message(msg)

So you are probably passing None to forward_message and attempting to use split on None. None does not have a split method which is causing this error.

Remove the second msg = radio.receive() so you are only passing message after checking if msg.

  msg = radio.receive()
  if msg:
    forward_message(msg)
foxyblue
  • 2,859
  • 2
  • 21
  • 29