After a power outage, 60 ESP32s enter an endless reconnect loop
Translated from Türkçe by AI ·
Hello, sorry in advance for the long post.We are planning to set up about 200 small ESP32-based measurement boxes at the water treatment plant where I work, for level, flow and pump status. All of them will be in the same building, connect to the same access point, and send data to Hermetry over MQTT. We first piloted with 60 of them.During normal operation there is no problem. But last week the building had a 20-minute power outage, and when power came back, most of the boxes could not connect properly. On the serial port I am watching one of them, there is a constant connect-drop cycle, and on the dashboard devices keep switching between online and offline. I checked the Log tab of the devices:
Connected via mqtts
Disconnected Reason: takeover
Connected via mqtts
Disconnected Reason: takeover
Also, the administrators received a notification called “takeover fight”.The first thing that comes to mind is the access point. We are using a home-type AP, it may be struggling with 60 clients, and I don’t know what will happen with 200. Meanwhile, to speed up the pilot, we flashed the same firmware and the same access token onto all the boxes. I’ll mention that too, I don’t know if it’s related.
Merhaba, uzun yazacağım kusura bakmayın.
Çalıştığım su arıtma tesisinde seviye, debi ve pompa durumları için yaklaşık 200 tane ESP32 tabanlı küçük ölçüm kutusu kurmayı planlıyoruz. Hepsi aynı binada, aynı erişim noktasına bağlanacak, MQTT ile Hermetry’ye gidecek. Önce 60 tanesiyle pilot yaptık.
Normal çalışırken sorun yok. Ama geçen hafta binada 20 dakikalık elektrik kesintisi oldu, elektrik gelince kutuların çoğu bir türlü düzgün bağlanamadı. Seri porttan izlediğim birinde sürekli bağlan-düş var, dashboard’da cihazlar bir çevrimiçi bir çevrimdışı. Cihazların Log sekmesine baktım:
Connected via mqtts
Disconnected Reason: takeover
Connected via mqtts
Disconnected Reason: takeover
Bir de yöneticilere “takeover fight” diye bir bildirim gelmiş.
İlk aklıma gelen erişim noktası oldu. Ev tipi bir AP kullanıyoruz, 60 istemcide zorlanıyor olabilir, 200’de ne olacak bilmiyorum. Bu arada pilotta hız kazanmak için tüm kutulara aynı firmware’i ve aynı access token’ı yükledik, bir de onu yazayım, alakası var mı bilmiyorum.
Translated from Türkçe by AI ·
Most consumer APs get clogged at 30-50 clients, I think that’s where the problem is. We need an enterprise AP.
Ev tipi AP’lerin çoğu 30-50 istemcide tıkanır, bence sorun orada. Kurumsal bir AP lazım.
Translated from Türkçe by AI ·
İlgaz is right about the AP, but the takeover in the log is saying something else, and the main cause is the last sentence you wrote.In Hermetry, each device gets a single session. When a second connection from the same device arrives, it closes the first one and takes over. When 60 boxes connect with the same token, Hermetry sees them as one device: each new connection drops the previous one, the dropped one reconnects, and it loops endlessly. A device that keeps doing this from two networks is held back for a while, and that is the “takeover fight” notification. Normally the connections are spread out so you wouldn’t have noticed, but when power came back and all 60 went down and up at the same time, it blew up.What to do:1. Give each box its own credentials. Instead of adding 200 devices one by one, you can do a bulk CSV import from the Imports page (up to 1,000 rows per file). It shows a dry run first, and the tokens for new devices come in a file that can be downloaded only once. Alternatively, you can use a provisioning key in the profile so each device gets its own token on first boot.2. Add a random delay before reconnecting. If CONNACK 3 comes back, wait and retry, but don’t let them all retry in the same second:
uint32_t backoff = 2000 + (esp_random() % 8000); // 2-10 sn
if (!mqtt.connected()) { delay(backoff); mqtt.connect(id, token, ""); }
3. Keepalive between 30 and 300 seconds. 60 is good.4. Don’t rely on a single home-type AP for 200 boxes; split them across 2-3 enterprise APs.Session and CONNACK details are on the MQTT page.
AP konusunda İlgaz haklı ama Log’daki takeover başka bir şey söylüyor, asıl sebep son yazdığın cümle.
Hermetry’de her cihazın tek bir oturumu olur. Aynı cihazın ikinci bağlantısı gelince birincisini kapatıp devralır. 60 kutu aynı token’la bağlanınca Hermetry bunları tek bir cihaz olarak görüyor: her bağlanan bir öncekini düşürüyor, düşen tekrar bağlanıyor, sonsuz döngü. Bunu iki ağdan sürekli yapan cihaz bir süre geri tutuluyor ve “takeover fight” bildirimi o. Normalde bağlantılar dağınık olduğu için fark etmemişsiniz, elektrik gelince 60’ı aynı anda kalkınca patlamış.
Ne yapmalı:
1. Her kutuya kendi kimlik bilgisi. 200 cihazı tek tek açmak yerine Imports sayfasından CSV ile toplu içe aktarma yapılabiliyor (dosya başına 1.000 satıra kadar), önce kuru çalıştırma gösteriyor, yeni cihazların token’ları bir kere indirilebilen bir dosyada geliyor. Alternatif olarak profilde provisioning key ile cihazların ilk açılışta kendi token’ını almasını sağlayabilirsiniz. 2. Yeniden bağlanmaya rastgele gecikme ekleyin. CONNACK 3 gelirse bekle-tekrar dene, ama hepsi aynı saniyede denemesin:
uint32_t backoff = 2000 + (esp_random() % 8000); // 2-10 sn
if (!mqtt.connected()) { delay(backoff); mqtt.connect(id, token, ""); }
3. Keepalive 30-300 saniye arası. 60 iyi. 4. 200 kutu için tek ev tipi AP’ye güvenmeyin, 2-3 tane kurumsal AP’ye bölün.
Oturum ve CONNACK detayları MQTT sayfasında.
Translated from Türkçe by AI ·
Esra, thanks a lot, that’s exactly how it was. I imported the 60 devices via CSV, and we loaded the tokens from the file I downloaded into the boxes by serial number. Yesterday we deliberately pulled out the fuse and reinserted it, and all of them connected cleanly within 15 seconds, with no single takeover in the Log.We also changed the AP: as we scale to 200, we’re splitting it across three ceiling-type APs.
Esra çok teşekkürler, aynen öyleymiş. 60 cihazı CSV ile içe aktardım, indirdiğim dosyadaki token’ları seri numarasına göre kutulara yükledik. Dün bilerek sigortayı indirip kaldırdık, hepsi 15 saniye içinde temiz bağlandı, Log’da tek takeover yok.
AP’yi de değiştirdik, 200’e geçerken üç tavan tipi AP’ye bölüyoruz.
Translated from Türkçe by AI ·
+1 for jitter. We also had a field case where 40 sensors trying to connect at the same time caused some of them to hit address blocking; it was resolved with a random delay.
+1 jitter için. Bizde de bir sahada 40 sensör aynı anda bağlanmaya çalışınca bazıları adres engellemesine takılmıştı, rastgele gecikmeyle düzeldi.
- You must be logged in to reply to this topic.
Join the conversation
Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

