コード例 #1
0
def radio_contact(message): #Fonction d'envoi de données et réception de réponses
        messageArray = message.split("/")
        if messageArray[1] == "cmd":
            status = messageArray[2]
            if (status == "TL"):
                STATUS = "LT"
            else :
                STATUS = "TL"
            temp = str(temperature())
            lum = str(display.read_light_level())
            txt_Temp = "Temp = " + temp
            txt_Lum =  "Lum = " + lum
            if (STATUS == "TL"):
                clear_oled()
                add_text(0, L1, txt_Temp)
                add_text(0, L2, txt_Lum)
            else:
                clear_oled()
                add_text(0, L2, txt_Temp)
                add_text(0, L1, txt_Lum)

        elif messageArray[1] == "ans":
            SENSOR_ID = messageArray[2]

        else:
            radio.send("00/error/umr")
コード例 #2
0
import random
##################################################

# Global variables
##################################################
# Network request
init = "CHLIB_REQUEST"
accept = "CHLIB_ACCEPT"
stop = "CHLIB_STOP"
# Default communication addresse
default_address = "0x12345678"
# Default key for cipher
key = default_address
# Initialize screen
initialize(pinReset=pin0)
clear_oled()
# Communication not established by default
com_established = False

##################################################


# Network functions
##################################################
# Send message by radio to another micro:bit
# Encrypt the message before to send
def send_msg(message):
    q = vign(message, key, 'e')
    radio.send(q)  # max size 251 bytes (octets)