<?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[Code only works from Visual Studio]]></title><description><![CDATA[<p dir="auto">I have this code:</p>
<pre><code>def main():
  purple_air = PurpleAir()
  # Reset orientation when A pushed. End test if testing.
  btnA.wasPressed(purple_air.SetOrientation)
  btnB.wasPressed(purple_air.Testing)

  wifi_try_count = 0
  while True:  while True:
    if not (wifiCfg.wlan_sta.isconnected()):
      wifi_try_count += 1
      purple_air.ShowError(
        'No WiFi ({:d})'.format(wifi_try_count))
      wifiCfg.doConnect('FBI', 'CIA')
      purple_air.ShowError('WiFi connected')
    else:
      purple_air.ShowError('Trying')
      try:
        purple_air.GetAQI()
      except Error as e:
        purple_air.ShowError(e)
    purple_air.ShowError('Waiting')
    wait_ms(1)
    purple_air.ShowError('Done')
</code></pre>
<p dir="auto">When I run from Visual Studio, it connects to WiFi, prints WiFi Connected, Waiting, Done, Trying all in a row.</p>
<p dir="auto">When I disconnect it, choose it from the App screen, it will stop at WiFi Connected. If I yank out the entire else clause, then it will stop at Waiting. In either case, exactly 1 print statement after connecting to WiFi.</p>
<p dir="auto">It's not actually <em>completely</em> dead: Pressing the A  or B buttons execute the callbacks as expected.</p>
<p dir="auto">But I can't figure out why it reacts differently connected vs. unconnected!</p>
<p dir="auto">Any ideas?</p>
]]></description><link>https://community.m5stack.com/topic/1898/code-only-works-from-visual-studio</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 03:33:21 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/1898.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Apr 2020 05:29:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Code only works from Visual Studio on Fri, 01 May 2020 01:48:28 GMT]]></title><description><![CDATA[<p dir="auto">Given that I can now see the console, I determined that it throws OSError if the http GET fails. Which is a weird error to throw, but OK. So I put that in my <code>except:</code> clause, and it's humming away!</p>
]]></description><link>https://community.m5stack.com/post/8453</link><guid isPermaLink="true">https://community.m5stack.com/post/8453</guid><dc:creator><![CDATA[dclaar]]></dc:creator><pubDate>Fri, 01 May 2020 01:48:28 GMT</pubDate></item><item><title><![CDATA[Reply to Code only works from Visual Studio on Thu, 30 Apr 2020 15:11:11 GMT]]></title><description><![CDATA[<p dir="auto">I noticed that some development environments use REPL when transferring files and running.  And by the way, they silently import various system libraries / modules.  Eg uPyCraft imports <strong>os</strong> library to display a list of files.  By the way, the <strong>wait_ms ()</strong> can be imported from the <strong>time</strong> library</p>
]]></description><link>https://community.m5stack.com/post/8451</link><guid isPermaLink="true">https://community.m5stack.com/post/8451</guid><dc:creator><![CDATA[robalstona]]></dc:creator><pubDate>Thu, 30 Apr 2020 15:11:11 GMT</pubDate></item><item><title><![CDATA[Reply to Code only works from Visual Studio on Thu, 30 Apr 2020 03:40:02 GMT]]></title><description><![CDATA[<p dir="auto">I was trying to be "more pythonic" and not <code>import *</code>, i.e.</p>
<pre><code>from m5stack import lcd
</code></pre>
<p dir="auto">It didn't occur to me that it was in uiflow!<br />
I've gone back to importing everything. :)</p>
]]></description><link>https://community.m5stack.com/post/8444</link><guid isPermaLink="true">https://community.m5stack.com/post/8444</guid><dc:creator><![CDATA[dclaar]]></dc:creator><pubDate>Thu, 30 Apr 2020 03:40:02 GMT</pubDate></item><item><title><![CDATA[Reply to Code only works from Visual Studio on Thu, 30 Apr 2020 02:57:34 GMT]]></title><description><![CDATA[<p dir="auto">wait_ms is part of the uiflow class, did you import it at the start of your program?</p>
]]></description><link>https://community.m5stack.com/post/8443</link><guid isPermaLink="true">https://community.m5stack.com/post/8443</guid><dc:creator><![CDATA[lukasmaximus]]></dc:creator><pubDate>Thu, 30 Apr 2020 02:57:34 GMT</pubDate></item><item><title><![CDATA[Reply to Code only works from Visual Studio on Wed, 29 Apr 2020 15:48:02 GMT]]></title><description><![CDATA[<p dir="auto">I <a href="https://forum.m5stack.com/topic/1913/omg-serial-console" target="_blank" rel="noopener noreferrer nofollow ugc">found out</a> that you can actually get a serial console, and it says:</p>
<pre><code>Traceback (most recent call last):
  File "main.py", line 130, in &lt;module&gt;
  File "main.py", line 128, in &lt;module&gt;
  File "main.py", line 96, in GetAQI
NameError: name 'wait_ms' isn't defined
</code></pre>
<p dir="auto">Don't ask me why it works when connected to the laptop, though!</p>
<p dir="auto">Serves me right for trying to limit the imports. :)</p>
]]></description><link>https://community.m5stack.com/post/8434</link><guid isPermaLink="true">https://community.m5stack.com/post/8434</guid><dc:creator><![CDATA[dclaar]]></dc:creator><pubDate>Wed, 29 Apr 2020 15:48:02 GMT</pubDate></item><item><title><![CDATA[Reply to Code only works from Visual Studio on Wed, 29 Apr 2020 03:35:24 GMT]]></title><description><![CDATA[<p dir="auto">Nope, spoke too soon. It just takes longer to hang. :(</p>
]]></description><link>https://community.m5stack.com/post/8423</link><guid isPermaLink="true">https://community.m5stack.com/post/8423</guid><dc:creator><![CDATA[dclaar]]></dc:creator><pubDate>Wed, 29 Apr 2020 03:35:24 GMT</pubDate></item><item><title><![CDATA[Reply to Code only works from Visual Studio on Wed, 29 Apr 2020 03:19:51 GMT]]></title><description><![CDATA[<p dir="auto">OK, I have no idea why, but taking out the <code>else:</code> works. (I took out <code>main()</code> first, and that didn't help, but I didn't put it back in once things worked). I haven't run it for a long time, so it might still hang, but initial indications are promising!</p>
<pre><code>while True:
  if not (wifiCfg.wlan_sta.isconnected()):
    wifi_try_count += 1
    purple_air.ShowError(
      'No WiFi ({:d})'.format(wifi_try_count))
    wifiCfg.doConnect('Mi5', 'double07')
    purple_air.ShowError('WiFi connected')
  try:
    purple_air.GetAQI()
  except Error as e:
    purple_air.ShowError(e)
  wait_ms(1)
</code></pre>
]]></description><link>https://community.m5stack.com/post/8422</link><guid isPermaLink="true">https://community.m5stack.com/post/8422</guid><dc:creator><![CDATA[dclaar]]></dc:creator><pubDate>Wed, 29 Apr 2020 03:19:51 GMT</pubDate></item></channel></rss>