Implementing Greenhouse Monitoring via Mobile IoT Applications
A greenhouse is a closed environment where every parameter affects yield. Temperature, humidity, CO₂, light intensity, soil moisture, pH and EC of nutrient solution — all must be tracked in real-time. Unlike open fields, greenhouses have good connectivity (Wi-Fi, Zigbee), but strict reliability requirements: critical temperature drop or humidifier failure can destroy the crop in hours.
Sensors and Protocols
Standard set for one greenhouse section:
- Air temperature/humidity: SHT40 (I²C), DHT22 (One-Wire) — on ESP32-based nodes
- CO₂: MH-Z19B (UART) or SenseAir S8 (Modbus)
- Light intensity: VEML7700 (I²C), lux and photosynthetically active radiation (PAR)
- Soil moisture: TEROS 12 (SDI-12)
- EC/pH of nutrient solution: Atlas Scientific EZO-EC and EZO-pH (I²C UART)
Nodes on ESP32 with ESPHome or Tasmota firmware publish data to MQTT. Home Assistant or custom MQTT broker (Mosquitto) aggregates. Mobile application — via REST API or WebSocket on backend.
Real-Time via MQTT: Android
class GreenhouseMonitorService : Service(), MqttCallbackExtended {
private lateinit var mqttClient: MqttAndroidClient
private val sectionData = ConcurrentHashMap<String, GreenhouseSectionState>()
fun startMonitoring(sections: List<String>) {
sections.forEach { sectionId ->
mqttClient.subscribe("greenhouse/$sectionId/+", 1)
}
}
override fun messageArrived(topic: String, message: MqttMessage) {
val parts = topic.split("/")
val sectionId = parts[1]
val parameter = parts[2]
val value = String(message.payload).toDoubleOrNull() ?: return
val current = sectionData.getOrPut(sectionId) { GreenhouseSectionState(sectionId) }
val updated = when (parameter) {
"temperature" -> current.copy(temperatureC = value)
"humidity" -> current.copy(humidityPercent = value)
"co2" -> current.copy(co2Ppm = value.toInt())
"light_lux" -> current.copy(lightLux = value.toInt())
"soil_moisture" -> current.copy(soilMoistureVwc = value)
"ec" -> current.copy(nutrientEc = value)
"ph" -> current.copy(nutrientPh = value)
else -> current
}
sectionData[sectionId] = updated
broadcastUpdate(updated)
}
}
Section Dashboard
For greenhouses with multiple sections — horizontal PageView or TabBar with each section dashboard. Each section card displays color indicators for parameters: green (normal), yellow (warning), red (critical).
Threshold ranges for tomatoes as example:
| Parameter | Critical Low | Normal | Critical High |
|---|---|---|---|
| Night Temperature | < 12°C | 15-18°C | > 25°C |
| Day Temperature | < 18°C | 22-28°C | > 35°C |
| Humidity | < 50% | 65-80% | > 90% |
| CO₂ | < 400 ppm | 800-1200 ppm | > 1500 ppm |
| Solution EC | < 1.5 | 2.0-3.5 | > 5.0 |
| Solution pH | < 5.5 | 5.8-6.5 | > 7.0 |
Backend stores threshold configuration; mobile app downloads on startup and caches in SharedPreferences.
Climate Control: Operating Device Management
Greenhouse is not just monitoring. Vents, heaters, humidifiers, CO₂ generators are controlled from the app. MQTT commands to relays:
Future<void> setVentilation(String sectionId, bool open) async {
_mqttClient.publishMessage(
'greenhouse/$sectionId/vent/command',
MqttQos.exactlyOnce,
(MqttClientPayloadBuilder()..addString(open ? 'OPEN' : 'CLOSE')).payload!,
);
}
For automatic scenarios (open vents if temperature > 28°C), logic can be on backend (Node-RED, Home Assistant automation) or in the app as local rules.
Alerts: Critical Events
Greenhouse alerts are not just notifications. Below-zero temperature at night means heater failed, immediate action needed.
On Android: FCM with PRIORITY_HIGH + Foreground Service with Wake Lock for reliable delivery in night mode. On iOS: Critical Alerts via entitlement com.apple.developer.usernotifications.critical-alerts — play at full volume regardless of Do Not Disturb mode.
Additionally — voice call via Twilio Voice API for responsible persons if alert unconfirmed for 10 minutes.
Event Log and Reports
Agronomist views not just current data but history: when heater turned on, when vents opened, what temperature was at 2 AM. Event log with filtering by type and period is critical.
Report export to Excel/CSV — requirement for most industrial clients to document growing conditions. Generated on backend, mobile app downloads and opens via Share Sheet (iOS) or FileProvider (Android).
Developing greenhouse monitoring app with real-time, climate control and critical alerts: 5-8 weeks. Multi-section greenhouse with full logging and export: 2-3 months. Cost calculated individually.







