Skip to content

Instantly share code, notes, and snippets.

$ python main.py --endpoint AWS_IOT_ENDPOINT --rootCA root-ca-cert.pem --cert <device>.cert.pem --key <device>.private.key --thingName <device_name> --topic 'ble/discovered_device' --mode publish
$ sudo -E ./gg-device-setup-latest.sh bootstrap-greengrass-interactive
$ wget -q -O ./gg-device-setup-latest.sh https://d1onfpft10uf5o.cloudfront.net/greengrass-device-setup/downloads/gg-device-setup-latest.sh && chmod +x ./gg-device-setup-latest.sh && sudo -E ./gg-device-setup-latest.sh bootstrap-greengrass-interactive
$ export AWS_ACCESS_KEY_ID=<user-access-key-here>
$ export AWS_SECRET_ACCESS_KEY=<user-secret-key-here>
def enable_notify(peripheral, service_uuid, char_uuid):
setup_data = b"\x01\x00"
svc = peripheral.getServiceByUUID(service_uuid)
print(svc)
ch = peripheral.getCharacteristics(uuid=char_uuid)[0]
print(ch)
print('Characteristic handle: %d' % ch.valHandle)
# attempt connecting
try:
print('Connecting to ' + device_addr)
_ble_peripheral = btle.Peripheral(device_addr, addrType=btle.ADDR_TYPE_RANDOM)
_ble_peripheral.withDelegate(_ble_delegate)
# Setup to turn notifications on, e.g.
enable_notify(_ble_peripheral, IMU_SERVICE_UUID, IMU_SAMPLE_CHAR_UUID)
except Exception as e:
print(e)
from bluepy import btle
from bluepy.btle import Scanner, DefaultDelegate
from ble_delegate import ble_delegate
# delegate instance
params = [None]
_ble_delegate = ble_delegate(params) # params is whatever you need
# assign the delegate to the scanner
scanner = Scanner().withDelegate(_ble_delegate)
from bluepy import btle
from bluepy.btle import Scanner, DefaultDelegate
class ble_delegate(DefaultDelegate):
def __init__(self, params):
btle.DefaultDelegate.__init__(self)
# ... initialise here
def handleDiscovery(self, dev, isNewDev, isNewData):
if isNewDev:
#define T_SAFE 10 // minimum low/high in one duty cycle to avoid zero value
#define T_MIN 500 // min value for HIGH period
#define T_MAX 2500 // max value for HIGH period
#define T T_MAX+T_SAFE // duty cycle for servo motor in micro-seconds
int servo_pin = 9; // PWM pin
void setup() {
pinMode(servo_pin, OUTPUT); // sets the pin as output