<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ESP-NOW and two M5Stick C]]></title><description><![CDATA[<p dir="auto">I am experimenting with ESP-NOW and two M5Stick Cs.</p>
<p dir="auto">The application is designed for two people living in the same house. The two people are often in their own rooms studying. And they scare each other to death when they enter the room to discuss something.</p>
<p dir="auto">The application is designed so that when one of the two people goes to visit the other, clicks on button A, a 5-second timer starts. If the other person does not want the visit because they are in a moment of concentration, they press the A button on their device and a message appears on the device of the person who sent the request that it is not a good time with a red circle. If he/she does nothing, a green circle shows that the invitation to the meeting is agreed by both.</p>
<p dir="auto">I have been able to get it, except for the part where the other person clicks the A button, it does nothing. It continues the counter and does not show the red circle.</p>
<p dir="auto">I don't know if it's the nature of the ESP-NOW communication or if it's because something is wrong with my programming.</p>
<p dir="auto"><img src="/assets/uploads/files/1612696957135-a-resized.png" alt="0_1612696956071_a.png" class=" img-fluid img-markdown" /><br />
<img src="/assets/uploads/files/1612696967672-b-resized.png" alt="0_1612696967603_b.png" class=" img-fluid img-markdown" /></p>
<pre><code class="language-from">from m5ui import *
from uiflow import *
import espnow
import wifiCfg
import time

setScreenColor(0x111111)


status_str = None
my_mac_addr = None
a = None
d = None
f = None
status = None
mynameis = None
i = None

wifiCfg.wlan_ap.active(True)
wifiCfg.wlan_sta.active(True)
espnow.init()
circle0 = M5Circle(40, 115, 32, 0xe60909, 0xFFFFFF)
status_label = M5TextBox(74, 6, "status_label", lcd.FONT_Default, 0xFFFFFF, rotate=90)
count_label = M5TextBox(17, 83, "5", lcd.FONT_DejaVu72, 0xFFFFFF, rotate=0)
console_log = M5TextBox(12, 11, "console_log", lcd.FONT_DefaultSmall, 0xa9a4e6, rotate=90)
mynameis_label = M5TextBox(52, 11, "My name is:", lcd.FONT_DefaultSmall, 0xFFFFFF, rotate=90)


def longblink():
  global status_str, my_mac_addr, f, a, d, status, mynameis, i
  M5Led.on()
  wait_ms(500)
  M5Led.off()

def hello_from_the_other():
  global status_str, my_mac_addr, f, a, d, status, mynameis, i
  count_label.hide()
  shortblink()
  circle0.show()
  for i in range(6):
    circle0.setBgColor(0xffffff)
    circle0.setSize((i * 6 + 8))
    wait(1)
    if status != 'hello':
      circle0.setBgColor(0xff0000)
      longblink()
      break
    if i == 5:
      circle0.show()
      circle0.setBgColor(0x33cc00)
      shortblink()
  restart()

def inicialize():
  global status_str, my_mac_addr, f, a, d, status, mynameis, i
  mynameis_label.setText(str(mynameis))
  count_label.hide()
  circle0.hide()
  status = 'waiting'
  status_label.setText(str(status))

def hello():
  global status_str, my_mac_addr, f, a, d, status, mynameis, i
  count_label.show()
  shortblink()
  for i in range(5, -1, -1):
    count_label.setText(str(i))
    wait(1)
    if status != 'hello':
      circle0.show()
      circle0.setBgColor(0xff0000)
      longblink()
      break
    if i == 0:
      circle0.show()
      circle0.setBgColor(0x33cc00)
  restart()

def shortblink():
  global status_str, my_mac_addr, f, a, d, status, mynameis, i
  M5Led.on()
  wait_ms(50)
  M5Led.off()

def restart():
  global status_str, my_mac_addr, f, a, d, status, mynameis, i
  wait(6)
  inicialize()

def change_status(status_str):
  global my_mac_addr, f, a, d, status, mynameis, i
  status = status_str
  status_label.setText(str(status))
  espnow.send(id=1, data=str(status))



my_mac_addr = str((espnow.get_mac_addr()))
if my_mac_addr==:
  mynameis = 'Alice'
  espnow.add_peer('24:a1:60:45:6a:3d', id=1)
elif my_mac_addr==my_mac_addr:
  mynameis = 'Bob'
  espnow.add_peer('d8:a0:1d:56:b9:59', id=1)
else:
  mynameis = "I don't know"
inicialize()

def buttonA_wasPressed():
  global my_mac_addr, f, a, d, status, mynameis, status_str, i
  if status=='waiting':
    change_status('hello')
    hello()
  elif status=='hello':
    change_status('right_now_no_thanks')
  else:
    pass
  pass
btnA.wasPressed(buttonA_wasPressed)


def send_cb(flag):
  global my_mac_addr,f,a,d,status,mynameis,status_str,i
  f = flag
  if f:
    shortblink()
  else:
    status = 'not connected'
    status_label.setText(str(status))
    longblink()
    shortblink()
    longblink()
    shortblink()

  pass
espnow.send_cb(send_cb)



def recv_cb(_):
  global my_mac_addr,f,a,d,status,mynameis,status_str,i
  a, _, d = espnow.recv_data(encoder='str')
  shortblink()
  console_log.setText(str(d))
  if d=='hello':
    status = 'hello'
    status_label.setText(str(status))
    hello_from_the_other()
  elif d=='right_now_no_thanks':
    status = 'right_now_no_thanks'
    status_label.setText(str(status))
  else:
    pass

  pass
espnow.recv_cb(recv_cb)
</code></pre>
<p dir="auto"><a href="https://mega.nz/file/oQkiUA5L#GCb6eGua3_gVy4mO_hNPwVdYYaFcIFThjXJzfPPfWd8" target="_blank" rel="noopener noreferrer nofollow ugc">esp_now_busy.m5f file in MEGA</a></p>
]]></description><link>https://community.m5stack.com/topic/2908/esp-now-and-two-m5stick-c</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 15:36:43 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2908.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 07 Feb 2021 11:28:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ESP-NOW and two M5Stick C on Tue, 09 Feb 2021 17:59:46 GMT]]></title><description><![CDATA[<p dir="auto">Well, I hadn't thought of that! It reminded me of my MSX programming days. :D</p>
<p dir="auto">I'll try your proposal and I'll let you know.</p>
<p dir="auto">Thank you very much <a class="plugin-mentions-user plugin-mentions-a" href="/user/world101" aria-label="Profile: world101">@<bdi>world101</bdi></a>  for your reply.</p>
]]></description><link>https://community.m5stack.com/post/12368</link><guid isPermaLink="true">https://community.m5stack.com/post/12368</guid><dc:creator><![CDATA[mario]]></dc:creator><pubDate>Tue, 09 Feb 2021 17:59:46 GMT</pubDate></item><item><title><![CDATA[Reply to ESP-NOW and two M5Stick C on Mon, 08 Feb 2021 02:44:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mario" aria-label="Profile: mario">@<bdi>mario</bdi></a><br />
I tried your flow and I see what you are saying. I think your issue is that your program has loops containing waits, which is causing blocking in the code. So when the button A is pressed to respond to the request, it is not received by the button callback. My suggestion is to use some timers to minimize the blocking.</p>
]]></description><link>https://community.m5stack.com/post/12357</link><guid isPermaLink="true">https://community.m5stack.com/post/12357</guid><dc:creator><![CDATA[world101]]></dc:creator><pubDate>Mon, 08 Feb 2021 02:44:00 GMT</pubDate></item></channel></rss>