Skip to content

Blinker python library for hardware. Works with Raspberry Pi, linux, windows.

License

Notifications You must be signed in to change notification settings

i3water/blinker-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

blinker-py

Blinker python library for hardware. Works with Raspberry Pi, linux, windows.

What's Blinker

Blinker is a platform with iOS and Android apps to control embedded hardware like Arduino. You can easily build graphic interfaces for all your projects by simply dragging and dropping widgets.

Blinker 是一个运行在 IOS 和 Android 上用于控制嵌入式硬件的应用程序。你可以通过拖放控制组件,轻松地为你的项目建立图形化控制界面。

Reference/参考

Currently supported hardware

Connection types

  • Bluetooth Smart (BLE 4.0)
  • WiFi
  • MQTT

Prerequisites

You should have the following ready before beginning with hardware:

  • python 2.7.x

  • Install the simple-websocket-server
    pip install https://github.com/dpallot/simple-websocket-server.git

  • Install the python-zeroconf
    pip install https://github.com/jstasiak/python-zeroconf/archive/0.17.7.zip

Blinker Api

Configuration

Blinker.begin()

Call Blinker.begin() to configure Blinker:

Blinker.begin(...);

Choose different parameters based on the type of connection you use

BLE:

#define BLINKER_BLE  
#include <Blinker.h>  
  
void setup() {  
    Blinker.begin();  
}

SerialBLE Modules:
Blinker.begin() will config SoftWareSerial with default settings.

Blinker.begin();// default settings digital pins 2(RX) 3(TX) and baudrate 9600 bps
Blinker.begin(4, 5);// config digital pins 4(RX) 5(TX) with default baudrate 9600 bps
Blinker.begin(4, 5, 115200);// config digital pins 4(RX) 5(TX) and baudrate 115200 bps

WiFi:

#define BLINKER_WIFI  
#include <Blinker.h>  
  
void setup() {  
    Blinker.begin(ssid, pswd);  
}

MQTT:

#define BLINKER_MQTT  
#include <Blinker.h>  
  
void setup() {  
    Blinker.begin(auth, ssid, pswd);  
}

MQTT support hardware: WiFiduino, WiFiduino32, ESP8266, ESP32

begin() is basically doing these steps:
1.Configure hardware
2.Wait for connection app

Connection management

Blinker.connect()

This function will try onnecting to app.
Return true when connected, return false if timeout reached.
Default timeout is 10 seconds.

bool result = Blinker.connect();  
  

uint32_t timeout = 30000;//ms  
bool result = Blinker.connect(timeout);

Blinker.disconnect()

Disconnect Blinker connection

Blinker.disconnect();

Blinker.connected()

Get the status of Blinker connection

bool result = Blinker.connected();

Blinker.run()

This function should be called frequently to process incoming commands and perform of Blinker connection. It is usually called in void loop() {}

void loop() {
    Blinker.run();
}

Data management

Blinker.available()

Return true when data already arrived and stored in the receive buffer

bool result = Blinker.available();

Blinker.readString()

This function to reads characters from Blinker into a string.

String data = Blinker.readString();

*max read data bytes is 256bytes

Blinker.print()

Prints data to Blinker app

Blinker.print(data);

Prints a Json data to Blinkrt app, eg: {"temp":30.2}

Blinker.print("temp", 30.2);

Prints a Json data with unit to Blinkrt app, eg: {"temp":"30.2 °C"}

Blinker.print("temp", 30.2, "°C");

Json data can display in the Blinker TEXT widget

*max send data bytes is 128bytes

App Widgets

Blinker.wInit()

Init widget, Button Slider and Toggle widget recommended to initialize before use.

Blinker.wInit("ButtonName", W_BUTTON);  
Blinker.wInit("SliderName", W_SLIDER);  
Blinker.wInit("ToggleName", W_TOGGLE);//keyName, type  

type:
W_BUTTON Button
W_SLIDER Slider
W_TOGGLE toggle

Blinker.button()

Device receives an update of Button state from app, return true when Pressed, return false when Released.

bool result = Blinker.button("Button1");

Blinker.slider()

Return the latest update of Slider value from app

uint8_t result = Blinker.slider("Slider1");

Blinker.toggle()

Device receives an update of Toggle state from app, return true when ON, return false when OFF.

bool result = Blinker.toggle("ToggleKey1");

Blinker.joystick()

Return the latest update of Joystick value from app

uint8_t result_X = Blinker.joystick(J_Xaxis);
uint8_t result_Y = Blinker.joystick(J_Yaxis);

Blinker.ahrs()

Send AHRS attach commond to Blinker

Blinker.attachAhrs();

Return the latest update of AHRS value from app

int16_t result_Yaw = Blinker.ahrs(Yaw);
int16_t result_Roll = Blinker.ahrs(Roll);
int16_t result_Pitch = Blinker.ahrs(Pitch);

Send AHRS detach commond to Blinker

Blinker.detachAhrs();

Blinker.vibrate()

Send vibrate commond to Blinker, default vibration time is 500 milliseconds

Blinker.vibrate();
Blinker.vibrate(255);  

Delay

Blinker.delay()

This function can process incoming commands and perform of Blinker connection when delay

Blinker.delay(500);

Debug

To enable debug prints on the Serial, add this on the top of your sketch:

#define BLINKER_PRINTER Serial

Init & enable Serial in void setup() :

Serial.begin(115200);

You can also use spare HardWareSerial or SoftWareSerial for debug output (you will need an adapter to connect to it with your PC).

If you want debug output all detail :

#define BLINKER_PRINTER Serial
#define BLINKER_DEBUG_ALL  //add this behind

LOG

After enabled debug, you can use BLINKER_LOG() to debug output:

BLINKER_LOG1("detail message 1");  
BLINKER_LOG2("detail message 1", " 2");  
BLINKER_LOG3("detail message 1", " 2", " 3");  
BLINKER_LOG4("detail message 1", " 2", " 3", " 4");  
BLINKER_LOG5("detail message 1", " 2", " 3", " 4", " 5");  
BLINKER_LOG6("detail message 1", " 2", " 3", " 4", " 5", " 6");  

Thanks

WebSockets - for Blinker to build up a websocket server
Adafruit_MQTT_Library - for Blinker to build up a mqtt client


目前支持的硬件

连接类型

  • Bluetooth Smart (BLE 4.0)
  • WiFi
  • MQTT

准备工作

开始使用前你需要做好如下准备:

Blinker接口函数

设备配置

Blinker.begin()

使用 Blinker.begin() 来配置 Blinker:

Blinker.begin(...);

根据你使用的连接方式选择不同的参数用于配置Blinker

BLE:

#define BLINKER_BLE  
#include <Blinker.h>  
  
void setup() {  
    Blinker.begin();  
}

串口蓝牙模块:
Blinker.begin() 将使用默认设置配置 SoftWareSerial

Blinker.begin();// 默认设置: 数字IO 2(RX) 3(TX), 波特率 9600 bps
Blinker.begin(4, 5);// 设置数字IO 4(RX) 5(TX), 默认波特率 9600 bps
Blinker.begin(4, 5, 115200);// 设置数字IO 4(RX) 5(TX) 及波特率 115200 bps

WiFi:

#define BLINKER_WIFI  
#include <Blinker.h>  
  
void setup() {  
    Blinker.begin(ssid, pswd);  
}

MQTT:

#define BLINKER_MQTT  
#include <Blinker.h>  
  
void setup() {  
    Blinker.begin(auth, ssid, pswd);  
}

MQTT 支持的硬件: WiFiduino, WiFiduino32, ESP8266, ESP32

begin() 主要完成以下配置:
1.初始化硬件设置;
2.连接网络并广播设备信息等待app连接;

连接管理

Blinker.connect()

建立 Blinker 设备间连接并返回连接状态, 默认超时时间为10秒

bool result = Blinker.connect();  
  

uint32_t timeout = 30000;//ms  
bool result = Blinker.connect(timeout);

Blinker.disconnect()

断开 Blinker 设备间连接

Blinker.disconnect();

Blinker.connected()

返回 Blinker 设备间连接状态

bool result = Blinker.connected();

Blinker.run()

此函数需要频繁调用以保持设备间连接及处理收到的数据, 建议放在 loop() 函数中

void loop() {
    Blinker.run();
}

数据管理

Blinker.available()

检测是否有接收到数据

bool result = Blinker.available();

Blinker.readString()

读取接收到的数据

String data = Blinker.readString();

*读取数据最大为 256 字节

Blinker.print()

发送数据

Blinker.print(data);

发送一个Json数据, 如 {text1:data}

Blinker.print(text1, data);

发送一个带单位的Json数据, eg: {"temp":"30.2 °C"}

Blinker.print("temp", 30.2, "°C");

发送的Json数据可以在 Blinker APP 的 TEXT 组件中显示

*发送数据最大为 128 字节

App Widgets

Blinker.wInit()

组件初始化, 建议在使用前初始化 ButtonSliderToggle

Blinker.wInit("ButtonName", W_BUTTON);  
Blinker.wInit("SliderName", W_SLIDER);  
Blinker.wInit("ToggleName", W_TOGGLE);//键词, 类型  

类型:
W_BUTTON 按键
W_SLIDER 滑动条
W_TOGGLE 开关

Blinker.button()

读取开关/按键数据, 按下(Pressed)时返回true, 松开(Released)时返回false

bool result = Blinker.button("Button1");

Blinker.slider()

读取滑动条数据

uint8_t result = Blinker.slider("Slider1");

Blinker.toggle()

读取拨动开关数据, 打开(ON)时返回true, 关闭(OFF)时返回false

bool result = Blinker.toggle("Toggle1");

Blinker.joystick()

读取摇杆数据

uint8_t result_X = Blinker.joystick(J_Xaxis);
uint8_t result_Y = Blinker.joystick(J_Yaxis);

Blinker.ahrs()

开启手机 AHRS 功能

Blinker.attachAhrs();

读取 AHRS 数据

int16_t result_Yaw = Blinker.ahrs(Yaw);
int16_t result_Roll = Blinker.ahrs(Roll);
int16_t result_Pitch = Blinker.ahrs(Pitch);

关闭手机 AHRS 功能

Blinker.dettachAhrs();

Blinker.vibrate()

发送手机振动指令, 震动时间, 单位ms 毫秒, 数值范围0-1000, 默认为500

Blinker.vibrate();
Blinker.vibrate(255);  

设备延时

Blinker.delay()

延时函数, 在延时过程中仍保持设备间连接及数据接收处理

Blinker.delay(500);

*为了连接设备成功, 需要延时时务必使用该函数;
使用此函数可以在延时期间连接设备及接收数据并处理数据, 延时完成后才能执行后面的程序;

Debug

将这行代码添加到你的工程文件第一行, 以启用串口调试输出功能:

#define BLINKER_PRINTER Serial

void setup() 中初始化串口Serial :

Serial.begin(115200);

你可以用额外的硬件串口 (HardWareSerial) 或者软串口 (SoftWareSerial) 来调试输出 (你需要额外的适配器将该串口连接到你的电脑上).

如果你想调试输出更多细节信息 :

#define BLINKER_PRINTER Serial
#define BLINKER_DEBUG_ALL  //add this behind

LOG

开启调试输出 (Debug) 后可以使用 BLINKER_LOG() 打印输出调试信息:

BLINKER_LOG1("detail message 1");  
BLINKER_LOG2("detail message 1", " 2");  
BLINKER_LOG3("detail message 1", " 2", " 3");  
BLINKER_LOG4("detail message 1", " 2", " 3", " 4");  
BLINKER_LOG5("detail message 1", " 2", " 3", " 4", " 5");  
BLINKER_LOG6("detail message 1", " 2", " 3", " 4", " 5", " 6");  

感谢

WebSockets - Blinker 用这个库建立了一个 websocket 服务器
Adafruit_MQTT_Library - Blinker 用这个库建立了一个 MQTT 客户端

About

Blinker python library for hardware. Works with Raspberry Pi, linux, windows.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages