<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: م. Mohamed Salah</title>
    <description>The latest articles on DEV Community by م. Mohamed Salah (@mosalah_iot).</description>
    <link>https://dev.to/mosalah_iot</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4261634%2F4aba2c8b-664b-4b5d-af3d-8f80efc374fd.jpg</url>
      <title>DEV Community: م. Mohamed Salah</title>
      <link>https://dev.to/mosalah_iot</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mosalah_iot"/>
    <language>en</language>
    <item>
      <title>Four firmware lessons from senior embedded engineers, checked against two embedded prototypes</title>
      <dc:creator>م. Mohamed Salah</dc:creator>
      <pubDate>Tue, 24 Nov 2026 11:24:53 +0000</pubDate>
      <link>https://dev.to/mosalah_iot/what-senior-embedded-engineers-taught-me-and-where-it-shows-up-in-my-esp32-projects-315l</link>
      <guid>https://dev.to/mosalah_iot/what-senior-embedded-engineers-taught-me-and-where-it-shows-up-in-my-esp32-projects-315l</guid>
      <description>&lt;p&gt;I'm a 4th-year Computer Science &amp;amp; AI (IoT) student at MNU, and I build ESP32 projects. This article is a reading review: four pieces of writing by senior embedded engineers, the lesson in each one, and where that principle shows up (or is still missing) in two prototypes I have published on GitHub.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 1: never trust a single reading
&lt;/h2&gt;

&lt;p&gt;Jack Ganssle's classic &lt;a href="https://www.ganssle.com/debouncing.htm" rel="noopener noreferrer"&gt;A Guide to Debouncing&lt;/a&gt; is about switch contacts, but the core lesson is bigger: physical signals lie, briefly and often. Ganssle shows scope captures of buttons bouncing for milliseconds and walks through hardware and software ways to wait out the noise before believing an input.&lt;/p&gt;

&lt;p&gt;The same idea shows up in analog sensing. In the &lt;a href="https://github.com/mosalah34/smart-greenhouse-esp32" rel="noopener noreferrer"&gt;ESP32 greenhouse controller&lt;/a&gt; prototype, the soil-moisture reading does not switch the pump directly. The firmware uses hysteresis bands (irrigate below 35%, stop above 55%; fan on at 30 C, off at 27 C) plus a minimum pump rest time, so one noisy sample at the threshold cannot chatter the relay. Different signal, same principle: give the system a memory so a single bad reading stays a non-event.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 2: a watchdog is a design decision, not a checkbox
&lt;/h2&gt;

&lt;p&gt;Philip Koopman's &lt;a href="https://betterembsw.blogspot.com/2014/05/proper-watchdog-timer-use.html" rel="noopener noreferrer"&gt;Proper Watchdog Timer Use&lt;/a&gt; and his older &lt;a href="https://betterembsw.blogspot.com/2010/06/top-two-mistakes-with-watchdog-timers.html" rel="noopener noreferrer"&gt;Top two mistakes with watchdog timers&lt;/a&gt; state one warning very clearly: a watchdog that gets kicked blindly from a timer interrupt or the top of the main loop can keep a hung system running forever, because the kick proves the interrupt fires, not that the software is healthy.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://github.com/mosalah34/pulselink" rel="noopener noreferrer"&gt;PulseLink&lt;/a&gt;, an Arduino + Android monitoring prototype, the AVR watchdog is used deliberately and explicitly: the phone can send a RESET command that reboots the board through the watchdog, and the phone then waits longer than usual (up to 12 s) for the board to come back. That is a remote operator reset, not autonomous hang recovery, which is exactly the distinction Koopman's essays insist on. The open design question they raise for this prototype: if the watchdog is ever armed for autonomous recovery, the kick has to be conditional on real task health, not on a timer that fires no matter what.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 3: expect the link to drop
&lt;/h2&gt;

&lt;p&gt;Bluetooth and Wi-Fi links drop bytes, lines and whole connections. The PulseLink Android side treats this as normal: every command waits for an ACK line, with timeouts (3-3.5 s) and queued retries, and the parser refuses to treat unknown lines as data.&lt;/p&gt;

&lt;p&gt;HiveMQ's MQTT Essentials series, especially &lt;a href="https://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels/" rel="noopener noreferrer"&gt;Part 6 on Quality of Service levels&lt;/a&gt;, puts the same principle in protocol vocabulary. QoS 0 is fire-and-forget, QoS 1 guarantees at-least-once delivery at the cost of duplicates, QoS 2 costs more round trips for exactly-once. The greenhouse controller publishes its state over MQTT every 10 seconds, where a lost periodic update is harmless. Measured against those tradeoffs, the redesign candidate is clear: alerts are the messages that deserve QoS 1, routine telemetry can stay cheap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 4: silence is also a signal
&lt;/h2&gt;

&lt;p&gt;The flip side of lesson 3: when the sensor or the link goes completely quiet, a good system notices the silence itself. PulseLink's phone-side engine raises a SENSOR_DISCONNECTED alert if no valid reading arrives for 5 seconds, and the greenhouse firmware has a similar rule for acting safely when the soil sensor stops making sense. Designing for the absence of data is what turns a hang into a detected fault instead of a quiet wrong state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worth reading next
&lt;/h2&gt;

&lt;p&gt;More of Koopman's writing on embedded safety, and the &lt;a href="https://interrupt.memfault.com/" rel="noopener noreferrer"&gt;Interrupt blog by Memfault&lt;/a&gt;, where professional firmware engineers write up real debugging work. Recommendations for other authors on embedded reliability are welcome.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Projects referenced: &lt;a href="https://github.com/mosalah34/smart-greenhouse-esp32" rel="noopener noreferrer"&gt;smart-greenhouse-esp32&lt;/a&gt; and &lt;a href="https://github.com/mosalah34/pulselink" rel="noopener noreferrer"&gt;PulseLink&lt;/a&gt;, both learning prototypes published on GitHub, not medical or production devices.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>embedded</category>
      <category>esp32</category>
      <category>iot</category>
      <category>learning</category>
    </item>
    <item>
      <title>PulseLink: an Arduino + Android patient-monitoring prototype, and the problems its design solves</title>
      <dc:creator>م. Mohamed Salah</dc:creator>
      <pubDate>Tue, 24 Nov 2026 11:16:09 +0000</pubDate>
      <link>https://dev.to/mosalah_iot/pulselink-an-arduino-android-patient-monitoring-prototype-and-the-problems-its-design-solves-92a</link>
      <guid>https://dev.to/mosalah_iot/pulselink-an-arduino-android-patient-monitoring-prototype-and-the-problems-its-design-solves-92a</guid>
      <description>&lt;p&gt;I published PulseLink, an Arduino + Android patient-monitoring prototype.&lt;/p&gt;

&lt;p&gt;An Arduino UNO reads a pulse sensor and a DS18B20 temperature sensor and sends one line per second over an HC-05 Bluetooth module. A native Android app (Kotlin, Jetpack Compose, Room) shows live charts, decides when to alarm, and tells the Arduino to sound or silence its buzzer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problems the design had to solve, and how
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Noisy Bluetooth text:&lt;/strong&gt; a parser that accepts two telemetry formats and rejects malformed lines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lost commands:&lt;/strong&gt; every command waits for an ACK, with timeouts and queued retries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recovering a stuck board:&lt;/strong&gt; the phone can send a RESET command that reboots the Arduino through the AVR watchdog, with a longer timeout on the phone side while it restarts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A silent sensor:&lt;/strong&gt; if no valid reading arrives for 5 s, the app raises a stale-data alert.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Several alarms at once:&lt;/strong&gt; a priority order, with high temperature first.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Engineering details
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;th&gt;What the code does&lt;/th&gt;
&lt;th&gt;Where&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Two telemetry formats, noisy lines&lt;/td&gt;
&lt;td&gt;SerialProtocolParser reads &lt;code&gt;HR=..;TEMP=..;HR_ALARM=..;TEMP_ALARM=..&lt;/code&gt; and &lt;code&gt;HR:..,TEMP:..&lt;/code&gt;; unknown lines are not treated as data&lt;/td&gt;
&lt;td&gt;bluetooth/SerialProtocolParser.kt, tests&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Commands may be lost&lt;/td&gt;
&lt;td&gt;ArduinoCommander waits for ACK:* lines, 3 s and 3.5 s ACK timeouts, queued retries&lt;/td&gt;
&lt;td&gt;bluetooth/ArduinoCommander.kt&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stuck board&lt;/td&gt;
&lt;td&gt;RESET uses the AVR watchdog; the phone waits up to 12 s for the board to come back (SYSTEM_READY)&lt;/td&gt;
&lt;td&gt;firmware .ino, ArduinoCommander&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sensor or link goes silent&lt;/td&gt;
&lt;td&gt;stale-data timeout 5 s, SENSOR_DISCONNECTED alert&lt;/td&gt;
&lt;td&gt;engine/PhoneDecisionEngine.kt&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Many alarms together&lt;/td&gt;
&lt;td&gt;priority: HIGH_TEMPERATURE 10, HR alerts 5, SENSOR_DISCONNECTED 2&lt;/td&gt;
&lt;td&gt;engine/&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alarm fatigue&lt;/td&gt;
&lt;td&gt;AlarmStateMachine supports acknowledge and buzzer on/off&lt;/td&gt;
&lt;td&gt;engine/AlarmStateMachine.kt&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unreliable BPM&lt;/td&gt;
&lt;td&gt;firmware averages recent beat intervals, then applies a fixed correction (raw &amp;gt; 95 minus 40), applied once in the Arduino. A known limitation&lt;/td&gt;
&lt;td&gt;firmware&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Keeping data&lt;/td&gt;
&lt;td&gt;Room history and CSV export&lt;/td&gt;
&lt;td&gt;data/&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Default thresholds: HR below 50 low, above 100 high, temperature 35.0 C or higher critical. All configurable in Settings and labelled experimental in the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest status
&lt;/h2&gt;

&lt;p&gt;It is a prototype, not a medical device. The heart-rate correction is a fixed empirical adjustment. The repo includes unit tests; this release does not establish hardware validation.&lt;/p&gt;

&lt;p&gt;Code: &lt;a href="https://github.com/mosalah34/pulselink" rel="noopener noreferrer"&gt;https://github.com/mosalah34/pulselink&lt;/a&gt;&lt;/p&gt;

</description>
      <category>embedded</category>
      <category>iot</category>
      <category>kotlin</category>
      <category>arduino</category>
    </item>
    <item>
      <title>Designing an ESP32 Greenhouse Controller That Fails Safe</title>
      <dc:creator>م. Mohamed Salah</dc:creator>
      <pubDate>Tue, 24 Nov 2026 09:49:08 +0000</pubDate>
      <link>https://dev.to/mosalah_iot/designing-an-esp32-greenhouse-controller-that-fails-safe-4i51</link>
      <guid>https://dev.to/mosalah_iot/designing-an-esp32-greenhouse-controller-that-fails-safe-4i51</guid>
      <description>&lt;p&gt;I recently published the firmware for a smart greenhouse controller I have been working on: an ESP32 that reads soil moisture, air temperature and light, waters the plants and runs a ventilation fan on its own, and reports everything over MQTT. The control logic is exercised in a Python simulator for now, with on-hardware sensor calibration as the next step.&lt;/p&gt;

&lt;p&gt;The most interesting part of the project was not connecting the sensors. It was making sure the controller fails safe. Here are the three design decisions that mattered most, with code you can reuse.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Hysteresis, so the relays do not chatter
&lt;/h2&gt;

&lt;p&gt;The naive way to control a pump is &lt;code&gt;if (soil &amp;lt; threshold) pump on&lt;/code&gt;. The problem: soil moisture hovers right around the threshold, so the relay clicks on and off every few seconds. Relays die young that way, and the pump hates it too.&lt;/p&gt;

&lt;p&gt;The fix is two thresholds instead of one. Water below 35%, stop above 55%:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;soilPct&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;pumpCooldownOver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;pumpOn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;soilPct&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;55&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;pumpOff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fan gets the same treatment: on at 30 C, off at 27 C. Between the two values the controller simply keeps doing whatever it was already doing. That deadband is what makes a cheap relay board survive a real installation.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Every actuator gets a failsafe
&lt;/h2&gt;

&lt;p&gt;Ask "what breaks this?" for each output, then code the answer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pump run limit:&lt;/strong&gt; 60 seconds maximum per cycle. If a hose pops off or a sensor lies, the pump cannot run dry for hours.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mandatory rest:&lt;/strong&gt; 5 minutes between watering cycles, so soil has time to absorb water before the next reading. Without this, wet sensors read dry near the surface and you overwater.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sensor-loss rule:&lt;/strong&gt; if the DHT22 stops returning valid readings, irrigation is disabled entirely. A controller that cannot sense should not act.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last one is the rule I would put in any project: default to doing nothing when your inputs are untrustworthy.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Tune the logic in a simulator before touching hardware
&lt;/h2&gt;

&lt;p&gt;Analog soil sensors are not comparable between boards or even between sensors, so thresholds like 35% mean nothing until calibrated. I read the raw ADC value with the probe in dry air (&lt;code&gt;SOIL_DRY&lt;/code&gt;) and in water (&lt;code&gt;SOIL_WET&lt;/code&gt;) and map between them.&lt;/p&gt;

&lt;p&gt;But calibration only helps if the control rules around it are right. So the repo includes &lt;code&gt;simulator/simulate.py&lt;/code&gt;, a small Python model of soil drying and temperature drift that runs the exact same rules as the firmware:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python simulator/simulate.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This let me catch real problems, like pump rest time being shorter than the soil absorption time, without a plant in sight. When the hardware build happens, the thresholds get calibrated per sensor, but the logic arrives already tested.&lt;/p&gt;

&lt;h2&gt;
  
  
  Telemetry you can actually use
&lt;/h2&gt;

&lt;p&gt;Everything publishes to MQTT every 10 seconds as one JSON object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"temp_c"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;26.4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"humidity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;61.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"soil_pct"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"light_pct"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;72&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"pump"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"fan"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"manual"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One topic, one payload, so Node-RED or Home Assistant can chart it with zero parsing work. There is also a manual override mode through &lt;code&gt;greenhouse/1/cmd/*&lt;/code&gt; topics, because a system you cannot override is a system you will eventually have to unplug.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;Most of the value in an automation project is in the boring parts: hysteresis, timeouts, rest periods, and refusing to act on bad data. The sensor wiring takes an afternoon. Getting the failure behavior right is what makes it something you would leave running.&lt;/p&gt;

&lt;p&gt;Full firmware, wiring table and the simulator are on GitHub: &lt;a href="https://github.com/mosalah34/smart-greenhouse-esp32" rel="noopener noreferrer"&gt;smart-greenhouse-esp32&lt;/a&gt;. Feedback and war stories from your own builds are very welcome.&lt;/p&gt;

</description>
      <category>esp32</category>
      <category>iot</category>
      <category>mqtt</category>
      <category>embedded</category>
    </item>
  </channel>
</rss>
