Protocol Buffer Definitions
The Nano uses Protocol Buffers for structured data serialization. Below are the key message and enum definitions used in the device communication.
Message Types
Basic Values
message IntegerValue {
int32 value = 1;
}
message StringValue {
string value = 1;
}
message BoolValue {
bool value = 1;
}
Sensor Data
message SensorValue {
int32 value = 1; // Scaled by 10 for temperatures
UnitType units = 2; // Temperature unit
SensorType type = 3; // Type of sensor
}
message SensorValueList {
repeated SensorValue values = 1;
}
Device Information
message FirmwareInfo {
string commit_id = 1; // Git commit hash
string tag = 2; // Version tag
int32 date_code = 3; // Build date code
}
message DeviceStatus {
CookingState state = 1;
int32 target_temp = 2; // Scaled by 10
int32 current_temp = 3; // Scaled by 10
int32 timer_remaining = 4;
UnitType unit = 5;
}
Enumerations
Temperature Units
enum UnitType {
CELSIUS = 0;
FAHRENHEIT = 1;
}
Device States
enum CookingState {
IDLE = 0;
PREHEATING = 1;
COOKING = 2;
TIMER_COMPLETE = 3;
ERROR = 4;
}
Sensor Types
enum SensorType {
WATER_TEMP = 0;
TRIAC_TEMP = 1;
AMBIENT_TEMP = 2;
}
Command Domains
enum DomainType {
CONFIG = 1; // Configuration domain
}
Usage in BTLE Communication
Encoding Commands
When sending a command with a payload:
- Serialize the appropriate protocol buffer message
- Combine with domain and message type bytes
- COBS encode the complete message
- Append a zero byte terminator
Example process for setting temperature to 65.5°C:
1. Create IntegerValue with value 655 (65.5 × 10)
2. Serialize to binary format
3. Prepend [CONFIG_DOMAIN, SET_TEMP_SETPOINT]
4. COBS encode
5. Append 0x00 terminator
6. Transmit over BTLE
Decoding Responses
When receiving a response:
- Collect all chunks until message is complete
- Remove terminator byte (0x00)
- COBS decode
- Extract domain and message type
- Parse remaining payload using appropriate protocol buffer type
Example process for decoding sensor values:
1. Collect complete message
2. COBS decode
3. Extract domain and message type
4. Parse payload as SensorValueList
5. Process each sensor reading
Best Practices
Scale Factors
When working with temperature values:
// Encoding
scaled_temp = temperature_celsius * 10
// Decoding
actual_temp = sensor_value.value / 10.0
Message Handling
-
Define Protocol
// Using appropriate language-specific protobuf library
Define message types according to the schema above -
Serialize Messages
// Using protobuf serialization in your language
Convert message object to binary data -
Handle Responses
// Using protobuf parsing in your language
Parse binary data into appropriate message type
Message Size
Remember that BLE has a 20-byte MTU limit. Large protocol buffer messages will be automatically chunked during transmission.
Temperature Scale
For the Nano device, temperature values use a scale factor of 10 (not 100 as in other devices).