Developing Mobile Applications for Smart Buildings (BMS)
BMS projects always start the same way: customer shows a building diagram with Siemens Desigo CC, Schneider Electric EcoStruxure or Johnson Controls Metasys controllers and says "we want to see all this on the phone". Behind that "all this" are dozens of protocols, polling cycles from 1 second to 15 minutes, historical database spanning years, and requirement to work even when the main BMS server reboots.
Protocols and Gateways
Industrial BMS systems use BACnet/IP, Modbus TCP/RTU, KNX/IP and LonWorks. Mobile applications never communicate directly with controllers — a gateway or middleware sits between.
Typical integration stack:
| Layer | Technology |
|---|---|
| Controllers | BACnet/IP, Modbus TCP, KNX |
| Gateway | Node-RED, Niagara Framework 4, custom Python/Go service |
| Transport | MQTT over TLS, REST, WebSocket |
| Mobile Client | Flutter / Swift / Kotlin |
Niagara Framework 4 (Tridium) is de-facto standard for large objects. It normalizes BACnet objects into unified REST API (/haystack/api/read?filter=bacnet) and WebSocket change stream. Work with Haystack API via Dart:
class HaystackClient {
final Dio _dio;
final String _baseUrl;
HaystackClient(this._baseUrl, String username, String password) :
_dio = Dio(BaseOptions(
baseUrl: _baseUrl,
headers: {
'Authorization': 'Basic ${base64Encode(utf8.encode('$username:$password'))}',
'Accept': 'application/json',
},
));
Future<List<HaystackRow>> read(String filter) async {
final response = await _dio.get('/haystack/api/read',
queryParameters: {'filter': filter});
final grid = HaystackGrid.fromJson(response.data);
return grid.rows;
}
Future<Map<String, dynamic>> readPoint(String pointId) async {
final response = await _dio.get('/haystack/api/hisRead',
queryParameters: {
'id': '@$pointId',
'range': 'today',
});
return response.data;
}
}
For MQTT-gateway objects (Node-RED converts BACnet → MQTT JSON), use mqtt_client in Flutter. Organize topics by building hierarchy: building/{buildingId}/floor/{floor}/zone/{zone}/{parameter}.
Real-Time Data Architecture
The hardest part in BMS apps — not connection but data flow management. Temperature in 200 zones updates every 30 seconds, lighting by event, energy consumption every minute. Can't resubscribe on every UI redraw.
Solution — centralized DataHub at app level:
class BmsDataHub {
final MqttClient _mqtt;
final _streams = <String, BehaviorSubject<BmsPoint>>{};
Stream<BmsPoint> watchPoint(String pointId) {
if (!_streams.containsKey(pointId)) {
_streams[pointId] = BehaviorSubject();
_mqtt.subscribe('building/+/+/+/$pointId', MqttQos.atLeastOnce);
}
return _streams[pointId]!.stream;
}
void _onMessage(List<MqttReceivedMessage<MqttMessage>> events) {
for (final event in events) {
final topic = event.topic;
final payload = MqttPublishPayload.bytesToStringAsString(
(event.payload as MqttPublishMessage).payload.message);
final point = BmsPoint.fromJson(jsonDecode(payload));
_streams[point.id]?.add(point);
}
}
}
BehaviorSubject from rxdart keeps last value — widget subscribed after data arrives immediately gets current state without waiting for next poll cycle.
Interactive Floor Plan
Customers always want floor plan with live data. Convert DXF or SVG plan to SVG (via ODA File Converter for DXF), render via flutter_svg + InteractiveViewer. Sensor points are overlay over SVG positioned by normalized coordinates:
class FloorPlanWidget extends StatelessWidget {
final FloorPlan plan;
final Map<String, BmsPoint> liveData;
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return Stack(children: [
SvgPicture.asset('assets/floors/${plan.id}.svg',
width: constraints.maxWidth),
...plan.sensors.map((sensor) => Positioned(
left: sensor.x * constraints.maxWidth,
top: sensor.y * constraints.maxHeight,
child: SensorMarker(
point: liveData[sensor.pointId],
type: sensor.type,
),
)),
]);
});
}
}
Markers change color by thresholds: green (normal), yellow (warning), red (alarm). Thresholds come from BMS config, not hardcoded.
Control: Writing Values to BACnet Points
Reading is easier than writing. To command BACnet points (temperature setpoint, light on/off) via REST gateway:
Future<void> writePoint(String pointId, dynamic value) async {
// Optimistic UI update
_hub.updateLocally(pointId, value);
try {
await _api.put('/haystack/api/pointWrite', data: {
'id': '@$pointId',
'level': 8, // BACnet write priority (1-16, lower = higher)
'val': value,
'who': _authService.currentUser,
'duration': 'PT0S', // permanent
});
} on DioException catch (e) {
// Revert on error
_hub.revertLocally(pointId);
rethrow;
}
}
BACnet Priority Array is a detail often ignored then developers can't understand why temperature setpoint doesn't change: controller accepts commands but higher priority from BMS schedule (levels 2-4) overrides. Level 8 is standard for manual operator.
Alerts and Event Log
Alarms from BMS arrive via MQTT or WebSocket. Generate local push via flutter_local_notifications; server push (when app closed) via FCM with high priority (priority: high, content_available: true).
Event log: SQLite via drift for offline storage of 30 days history, paginated API load for older records.
Access Control
Different users see different floors/zones. Rights stored on backend; mobile client requests accessible objects at login and doesn't build routes to restricted resources. Attempt to write to forbidden point → HTTP 403 → local revert + user notification.
Developing mobile BMS client with floor plan display, real-time data via MQTT/WebSocket and setpoint control: 8–12 weeks. Full system supporting multiple facilities, historical charts, alerts and permissions: 4–6 months. Cost calculated individually after analyzing controller protocols and integration requirements.







