Skip to content

Instantly share code, notes, and snippets.

@electronut
electronut / bluey-beacon-2.py
Created July 9, 2017 06:08
bluey-beacon - python
data = None
while True:
for line in scanner.get_lines():
if line:
found_mac = line[14:][:12]
reversed_mac = ''.join(
reversed([found_mac[i:i + 2] for i in range(0, len(found_mac), 2)]))
mac = ':'.join(a+b for a,b in zip(reversed_mac[::2], reversed_mac[1::2]))
data = line[26:]
if mac == deviceId and len(data) == 66:
@electronut
electronut / bluey-beacon-1.py
Created July 9, 2017 06:06
bluey-beacon - python
class BLEScanner:
hcitool = None
hcidump = None
def start(self):
print('Start receiving broadcasts')
DEVNULL = subprocess.DEVNULL if sys.version_info > (3, 0) else open(os.devnull, 'wb')
subprocess.call('sudo hciconfig hci0 reset', shell = True, stdout = DEVNULL)
// one-shot flag for setting adv data
static volatile bool g_setAdvData = false;
/**@brief Function for handling the Battery measurement timer timeout.
*
* @details This function will be called each time the battery level measurement timer expires.
*
* @param[in] p_context Pointer used for passing some arbitrary information (context) from the
* app_start_timer() call to the timeout handler.
*/
@electronut
electronut / process_uid.py
Created June 14, 2017 09:28
Process BLE UUID to code format...
"""
process_uid.py
eg.
Input: 80c4a66b-ddb7-46e3-87bc-ae7053faf6ee
Output: 0xee,0xf6,0xfa,0x53,0x70,0xae,0xbc,0x87,0xe3,0x46,0xb7,0xdd,0x6b,0xa6,0xc4,0x80
electronut.in
@electronut
electronut / Bluey Beacon set_adv_data.c
Last active June 13, 2017 11:42
Bluey Beacon set_adv_data()
// set adv data
void set_adv_data(bool init)
{
uint32_t err_code;
ble_advdata_t advdata;
uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
ble_advdata_manuf_data_t manuf_data; // Variable to hold manufacturer specific data
// Initialize with easily identifiable data
@electronut
electronut / Bluey Beacon Main loop.c
Last active July 28, 2020 10:03
Bluey Beacon Main loop
int main(void)
{
uint32_t err_code;
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
ble_stack_init();
advertising_init();
timers_init();
advertising_start();
@electronut
electronut / bluey-beacon-main1.c
Last active June 12, 2017 06:16
bluey-beacon - advertising_init
static void advertising_init(void)
{
uint32_t err_code;
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
err_code = sd_ble_gap_device_name_set(&sec_mode,
@electronut
electronut / bluey-upload.py
Created June 4, 2017 07:19
Uploads DFU OTA bootloader to bluey board
"""
upload.py
Uploads DFU OTA bootloader to bluey board.
Electronut Labs
electronut.in
"""
@electronut
electronut / osc.py
Created November 26, 2015 09:57
A simple python matplotlib animation example that shows an oscillating circle.
"""
oscillating_circle.py
A simple matplotlib animation example that shows an oscillating circle.
electronut.in
"""
import matplotlib.pyplot as plt
import matplotlib.animation as animation
"""
ldr.py
Display analog data from Arduino using Python (matplotlib)
Author: Mahesh Venkitachalam
Website: electronut.in
"""
import sys, serial, argparse