Microphone Characteristic <c8546913-bf02-45eb-8dde-9f8754f4a32e> we can only READ, there is no notification or indication.We will periodically poll this characteristic in this project to get current value from microphone.
LED Control Characteristic <fcb89c40-c603-59f3-7dc3-5ece444a401b> we can READ, WRITE and INDICATE. In this project we will use only WRITE possibility. To control LEDs we must write 4 bytes into this characteristic: 0xff,0x00,0x00,0x00.
First byte 0xff are used to ON all 4 led. Other 3 bytes are RED,GREEN,BLUE colors. Any value from 0x00 to 0xff can be written for specified color. Combination of them create many pretty colors.
So if we write 0xff,0x00,0x00,0ff then we get the bright BLUE color for all four onboard LEDs.
As I mentioned above we will poll the microphone and constrain it value to the range from 0x00 to 0xff, and then write bytes array to the LED CONTROL Characteristic. But It would be bored and simple,so I add some smooth transition for our LED between values.
And finally ALARM. When obtained value from microphone will be higher than established treshold, our bot must send a message to Telegram account.
Here is a code:
from bluepy.btle import *
import struct
import thread
import telepot
from datetime import datetime
print datetime.now().time()
bot = telepot.Bot('HERE MUST BE YOUR TOKEN')
bot_data = bot.getMe()
print bot_data
response = bot.getUpdates()
print response
bot.sendMessage(HERE_ID_WHERE_YOU_WANT_TO_SEND_MESSAGE,"HELLO MAX")
def map(x, in_min, in_max, out_min, out_max):
return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min)
def SENSE_handle():
scanner = Scanner(0)
devices = scanner.scan(3)
for dev in devices:
print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
for (adtype, desc, value) in dev.getScanData():
print " %s = %s" % (desc, value)
num_ble = len(devices)
print num_ble
if num_ble==0:
return None
ble_mic = []
char_sensor = 0
non_sensor = 0
led_char = Characteristic
mic_char = Characteristic
led_handle =0
for i in range(num_ble):
try:
devices[i].getScanData()
ble_mic.append(Peripheral())
ble_mic[char_sensor].connect(devices[i].addr,devices[i].addrType)
char_sensor = char_sensor + 1
print "Connected %s device with addr %s " % (char_sensor, devices[i].addr)
except:
non_sensor = non_sensor + 1
try:
for i in range(char_sensor):
services = ble_mic[i].getServices()
characteristics = ble_mic[i].getCharacteristics()
for k in characteristics:
print k
if k.uuid=="fcb89c40-c603-59f3-7dc3-5ece444a401b":
print "LED CONTROL FOUND"
led_char = k
led_handle = k.getHandle()
if k.uuid == "c8546913-bf02-45eb-8dde-9f8754f4a32e":
print "MIC SENSOR FOUND"
mic_char = k
except:
return None
led_bytes =[0xFF,0x00,0x00,0x00]
last_value = 0x00
while True:
mic_data = mic_char.read()
mic_data_value =(ord(mic_data[1])<<8)+ord(mic_data[0])
led =map(mic_data_value, 4100, 9999, 0, 0xff)
print "LED :",led
print "LAST VAL:",last_value
if led >150:
bot.sendMessage(HERE_ID_WHERE_YOU_WANT_TO_SEND_MESSAGE,"SOUND ALERT"+str(datetime.now().time()))
if last_value < led:
while last_value<=led:
print "LAST VALUE LOWER"
led_bytes[1]=last_value
# led_bytes[2]=led
led_bytes[3]=last_value
s =""
for i in led_bytes:
s+=chr(i)
ble_mic[0].writeCharacteristic(led_handle,s,True)
last_value=last_value+10
if last_value > led:
print "LAST VALUE HIGHER"
while last_value>led:
led_bytes[1]=last_value
# led_bytes[2]=led
led_bytes[3]=last_value
s =""
for i in led_bytes:
s+=chr(i)
ble_mic[0].writeCharacteristic(led_handle,s,True)
last_value=last_value-10
last_value = led
while True:
SENSE_handle()
Microphone Characteristic <c8546913-bf02-45eb-8dde-9f8754f4a32e> we can only READ, there is no notification or indication.We will periodically poll this characteristic in this project to get current value from microphone.
LED Control Characteristic <fcb89c40-c603-59f3-7dc3-5ece444a401b> we can READ, WRITE and INDICATE. In this project we will use only WRITE possibility. To control LEDs we must write 4 bytes into this characteristic: 0xff,0x00,0x00,0x00.
First byte 0xff are used to ON all 4 led. Other 3 bytes are RED,GREEN,BLUE colors. Any value from 0x00 to 0xff can be written for specified color. Combination of them create many pretty colors.
So if we write 0xff,0x00,0x00,0ff then we get the bright BLUE color for all four onboard LEDs.
As I mentioned above we will poll the microphone and constrain it value to the range from 0x00 to 0xff, and then write bytes array to the LED CONTROL Characteristic. But It would be bored and simple,so I add some smooth transition for our LED between values.
And finally ALARM. When obtained value from microphone will be higher than established treshold, our bot must send a message to Telegram account.
Here is a code:
from bluepy.btle import *
import struct
import thread
import telepot
from datetime import datetime
print datetime.now().time()
bot = telepot.Bot('HERE MUST BE YOUR TOKEN')
bot_data = bot.getMe()
print bot_data
response = bot.getUpdates()
print response
bot.sendMessage(HERE_ID_WHERE_YOU_WANT_TO_SEND_MESSAGE,"HELLO MAX")
def map(x, in_min, in_max, out_min, out_max):
return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min)
def SENSE_handle():
scanner = Scanner(0)
devices = scanner.scan(3)
for dev in devices:
print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
for (adtype, desc, value) in dev.getScanData():
print " %s = %s" % (desc, value)
num_ble = len(devices)
print num_ble
if num_ble==0:
return None
ble_mic = []
char_sensor = 0
non_sensor = 0
led_char = Characteristic
mic_char = Characteristic
led_handle =0
for i in range(num_ble):
try:
devices[i].getScanData()
ble_mic.append(Peripheral())
ble_mic[char_sensor].connect(devices[i].addr,devices[i].addrType)
char_sensor = char_sensor + 1
print "Connected %s device with addr %s " % (char_sensor, devices[i].addr)
except:
non_sensor = non_sensor + 1
try:
for i in range(char_sensor):
services = ble_mic[i].getServices()
characteristics = ble_mic[i].getCharacteristics()
for k in characteristics:
print k
if k.uuid=="fcb89c40-c603-59f3-7dc3-5ece444a401b":
print "LED CONTROL FOUND"
led_char = k
led_handle = k.getHandle()
if k.uuid == "c8546913-bf02-45eb-8dde-9f8754f4a32e":
print "MIC SENSOR FOUND"
mic_char = k
except:
return None
led_bytes =[0xFF,0x00,0x00,0x00]
last_value = 0x00
while True:
mic_data = mic_char.read()
mic_data_value =(ord(mic_data[1])<<8)+ord(mic_data[0])
led =map(mic_data_value, 4100, 9999, 0, 0xff)
print "LED :",led
print "LAST VAL:",last_value
if led >150:
bot.sendMessage(HERE_ID_WHERE_YOU_WANT_TO_SEND_MESSAGE,"SOUND ALERT"+str(datetime.now().time()))
if last_value < led:
while last_value<=led:
print "LAST VALUE LOWER"
led_bytes[1]=last_value
# led_bytes[2]=led
led_bytes[3]=last_value
s =""
for i in led_bytes:
s+=chr(i)
ble_mic[0].writeCharacteristic(led_handle,s,True)
last_value=last_value+10
if last_value > led:
print "LAST VALUE HIGHER"
while last_value>led:
led_bytes[1]=last_value
# led_bytes[2]=led
led_bytes[3]=last_value
s =""
for i in led_bytes:
s+=chr(i)
ble_mic[0].writeCharacteristic(led_handle,s,True)
last_value=last_value-10
last_value = led
while True:
SENSE_handle()
This program can use in a EFM32,EZR32, EFR32 MCU. The WDS generated script files and patch file can download with a simple terminal to the MCU and the program convert the data to Pro2 API code and send to the SPI bus to PRO2 chip. Complete API Command, Property and Register read/write support.
The program communicate with the Pro2 chip over SPI bus and the PC over Uart or USB. The pc side needs a terminal program like UTTY The serial protocol supports the ANSI/ VT100 Terminal ESC sequences. The terminal settings are the following:
Flow control: RTS/CTS
Baud rate: 57600
8 data, no parity, 1 stop bits
Terminal type ANSI or VT100
The command line can edit with ‘Backspace/Home/End’ or ‘Left/Right’ cursor keys. The command line must be closed by ‘Enter’. The program trims all special character except the underscore“_” The excepted character list: “0-9”, “a-z”, “A-Z”, “space” and “_”.
I attached the detailed documentacion and the Bin file.
Just donwload the program into the Radio board flash.
It is an first version if you found a bug please report to me!
Projects
Thunderboard Sense kit Sound Alarm and notification in Telegram
Hello everyone.
Few days ago I received the new Thunderboard Sense kit and I decide to make sound alarm which will notify me on telegram.
Firstly I create bot and get token. How to do this you can read here https://core.telegram.org/bots
Then I install on my raspberypi bluepy and telepot modules for python
Ok! Now we are ready for experiments.
Firstly we need to know which characteristics are responsible for onboard LED and microphone sensor.
Let`s create simple python script and discover all present characteristics on Thunderboard Sense kit.
This is our result
Microphone Characteristic <c8546913-bf02-45eb-8dde-9f8754f4a32e> we can only READ, there is no notification or indication.We will periodically poll this characteristic in this project to get current value from microphone.
LED Control Characteristic <fcb89c40-c603-59f3-7dc3-5ece444a401b> we can READ, WRITE and INDICATE. In this project we will use only WRITE possibility. To control LEDs we must write 4 bytes into this characteristic: 0xff,0x00,0x00,0x00.
First byte 0xff are used to ON all 4 led. Other 3 bytes are RED,GREEN,BLUE colors. Any value from 0x00 to 0xff can be written for specified color. Combination of them create many pretty colors.
So if we write 0xff,0x00,0x00,0ff then we get the bright BLUE color for all four onboard LEDs.
As I mentioned above we will poll the microphone and constrain it value to the range from 0x00 to 0xff, and then write bytes array to the LED CONTROL Characteristic. But It would be bored and simple,so I add some smooth transition for our LED between values.
And finally ALARM. When obtained value from microphone will be higher than established treshold, our bot must send a message to Telegram account.
Here is a code:
And now video how it works
Thunderboard Sense kit Sound Alarm and notification in Telegram
Hello everyone.
Few days ago I received the new Thunderboard Sense kit and I decide to make sound alarm which will notify me on telegram.
Firstly I create bot and get token. How to do this you can read here https://core.telegram.org/bots
Then I install on my raspberypi bluepy and telepot modules for python
Ok! Now we are ready for experiments.
Firstly we need to know which characteristics are responsible for onboard LED and microphone sensor.
Let`s create simple python script and discover all present characteristics on Thunderboard Sense kit.
This is our result
Microphone Characteristic <c8546913-bf02-45eb-8dde-9f8754f4a32e> we can only READ, there is no notification or indication.We will periodically poll this characteristic in this project to get current value from microphone.
LED Control Characteristic <fcb89c40-c603-59f3-7dc3-5ece444a401b> we can READ, WRITE and INDICATE. In this project we will use only WRITE possibility. To control LEDs we must write 4 bytes into this characteristic: 0xff,0x00,0x00,0x00.
First byte 0xff are used to ON all 4 led. Other 3 bytes are RED,GREEN,BLUE colors. Any value from 0x00 to 0xff can be written for specified color. Combination of them create many pretty colors.
So if we write 0xff,0x00,0x00,0ff then we get the bright BLUE color for all four onboard LEDs.
As I mentioned above we will poll the microphone and constrain it value to the range from 0x00 to 0xff, and then write bytes array to the LED CONTROL Characteristic. But It would be bored and simple,so I add some smooth transition for our LED between values.
And finally ALARM. When obtained value from microphone will be higher than established treshold, our bot must send a message to Telegram account.
Here is a code:
And now video how it works
EZR32 WDS script donwload firmware (Easy config)
Description:
This program can use in a EFM32,EZR32, EFR32 MCU. The WDS generated script files and patch file can download with a simple terminal to the MCU and the program convert the data to Pro2 API code and send to the SPI bus to PRO2 chip. Complete API Command, Property and Register read/write support.
The API command are here: http://www.silabs.com/Support%20Documents/TechnicalDocs/EZRadioPRO_REVC2_API.zip
Features:
The Firmware
The program communicate with the Pro2 chip over SPI bus and the PC over Uart or USB. The pc side needs a terminal program like
UTTY The serial protocol supports the ANSI/ VT100 Terminal ESC sequences. The terminal settings are the following:
The command line can edit with ‘Backspace/Home/End’ or ‘Left/Right’ cursor keys. The command line must be closed by ‘Enter’. The program trims all special character except the underscore“_” The excepted character list: “0-9”, “a-z”, “A-Z”, “space” and “_”.
I attached the detailed documentacion and the Bin file.
Just donwload the program into the Radio board flash.
It is an first version if you found a bug please report to me!