SShortSingh.
Back to feed

Two-Beam People Counters: State Machines, Timeouts and Retained MQTT State

0
·4 views

A review examines three published sources on counting people with two beam sensors and checks them against an ESP32 prototype that reports over MQTT. The reference design detects entries and exits by which beam is blocked first, relying on a short timeout to discard incomplete crossings. Timeouts built on millis() must use unsigned elapsed-time arithmetic to handle the roughly 50-day rollover. The prototype follows the direction logic and rollover-safe timeout pattern, but keeps its count only in RAM, so reboots reset it and errors are never corrected automatically. Its state is published every 5 seconds without the retained flag, so dashboards connecting between messages must wait for the next update.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

How overtime is calculated when one worker earns two different hourly rates

Standard overtime calculators usually assume a single hourly rate, which does not fit workers who hold two roles at different pay. Under the US Fair Labor Standards Act, a mixed-rate week uses a weighted regular rate: total straight-time earnings divided by total hours worked. The author illustrates this with a 50-hour week at $20 and $14 an hour, yielding a $17.60 regular rate and $968 in total pay. Paying overtime at either individual job rate is incorrect, and the author notes that the only legal alternative requires an advance agreement. The method is built into the author's calculator at mytimecardcal.com.

0
ProgrammingDEV Community ·

React's use() Hook Requires Stable Promises to Avoid Infinite Re-suspension

A DEV Community article explains that React's use() hook can replace useEffect, useState, and cleanup logic for reading async values in components. Using use() directly on a freshly created promise on every render, however, causes an endless loop of suspending and refetching. The author shows that wrapping the promise in useMemo keeps its identity stable across renders so React recognizes the resolved value. The piece concludes that use() requires promises to come from a cached source, such as a memoizing parent component or a data cache.

0
ProgrammingDEV Community ·

Notifio's 38 pages have 151 unnamed image nodes and an unreadable live region, an accessibility-tree audit finds

A developer audited the accessibility tree of Notifio's website across 38 pages, using Chrome's DevTools protocol rather than reading raw HTML or tabbing through the site. The tree held 16,376 nodes, and most controls such as links, buttons, text fields and disclosures had accessible names. The audit found 151 unnamed graphic nodes, which screen readers would announce without any description, concentrated on the home page. It also found that the site had no region landmarks, since sections lacked accessible names. The author plans to fix the graphics by marking decorative icons as hidden from assistive technology.

0
ProgrammingDEV Community ·

TypeScript Template Literal Types Can Catch Object Path Typos at Compile Time

A common pattern passes dot-separated property paths as plain strings, so a misspelled key like "colros" compiles without error and fails only at runtime. The typical fix of using keyof only checks one level deep, which is insufficient for nested paths. The article shows how template literal types combined with recursive conditional mapped types can generate a union of every valid dot-path from an object's declared shape. Because the union is derived from the type itself rather than written by hand, typos are rejected by the compiler. The approach requires only about fifteen lines of code and relies on a feature available since TypeScript 4.1.