<?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[Error 118, doconnect() not connecting]]></title><description><![CDATA[<p dir="auto">I'm working on debugging this script. It's been a slow process since I can't run serial in VScode.</p>
<p dir="auto">It's collecting moisture readings and then sending them to a Adafruit IO feed through a POST. I found my way around th 113 errors from <code>urequests</code>, but now I'm getting <code>OSerror 118</code>. I guess this indicates the wifi isn't connected.</p>
<p dir="auto">I'm using <code>wifiCfg</code>'s doConnect function in a while loop in hopes that it will keep trying until it works. This works on an initial run, but it looks like it fails after a lightsleep.</p>
<p dir="auto">Does anyone have any idea about how I can get the wifi to connect more reliably? What am I missing?</p>
<pre><code>while(True):
  gc.collect()
  while not wifiCfg.doConnect('guest', '12345678', lcdShow=True): pass

  lcd.clear()
  lcd.setTextColor(0xaaaaaa, lcd.BLACK)
  lcd.font(lcd.FONT_DejaVu18)
  axp.setLcdBrightness(50)
  
  test.display(int(get_moisture()/10))
  wait(2)

  moisture = get_moisture() #get moisture
  try:
    response = urequests.request(
      method='POST',
      url='http://io.adafruit.com/api/v2/********/feeds/moisture/data',
      json={'value':moisture},
      headers={'Content-Type':'application/json','X-AIO-Key':'**************************'}
    )
    if response.status_code == 200:
      led.duty(99)
      lcd.clear()
      lcd.print("sent", lcd.CENTER, 5)
      lcd.image(0, 50, 'img/success.jpg')
      wait(1)
      axp.setLDO2Volt(0)
    else:
      lcd.print("request \r\n error", lcd.CENTER, 0, 0xFFFFFF)
      lcd.image(0, 50, 'img/error.jpg')
      led.duty(50)
      wait(10)
  except Exception as e:
    lcd.print("OS error", lcd.CENTER, 0, 0xFFFFFF)
    lcd.image(0, 50, 'img/error.jpg')
    print(e)
  
  gc.collect()
  lightsleep(60*1000)
</code></pre>
]]></description><link>https://community.m5stack.com/topic/1921/error-118-doconnect-not-connecting</link><generator>RSS for Node</generator><lastBuildDate>Sat, 02 May 2026 08:30:07 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/1921.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 01 May 2020 19:00:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Error 118, doconnect() not connecting on Sat, 02 May 2020 13:06:30 GMT]]></title><description><![CDATA[<p dir="auto">For anyone interested, I think I found the solution to my problem. The problem wasn't with <code>doConnect</code>.</p>
<p dir="auto">First, the 118 error was caused by lightsleep... I think. Since lightsleep allows RAM to persist, when it would wake up it would still think <code>wlan_sta</code> was active, even though it wasn't. Adding <code>wifiCfg.wlan_sta.active(False)</code> at the end turned the network off before going to sleep. That way each time it would connect as it should.</p>
<p dir="auto">Next, I kept getting error 23 after a few posts. This was caused by not closing the socket that was opened by the request and stored in response. The memory was filling up with socket objects, and running out of room. Calling <code>request.close()</code> removed the socket and freed up the memory. Now it's working just fine.</p>
]]></description><link>https://community.m5stack.com/post/8484</link><guid isPermaLink="true">https://community.m5stack.com/post/8484</guid><dc:creator><![CDATA[dwarrenku]]></dc:creator><pubDate>Sat, 02 May 2020 13:06:30 GMT</pubDate></item></channel></rss>