On Saturday, August 13, 2022 we will be working on the Adafruit Customer Support Forums. If you visit over the weekend and things are not complete yet, please check back later, https://adafruit.com/forumupdates
0

circuitPhyton IOT error: no module named 'socket'
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

circuitPhyton IOT error: no module named 'socket'

by will22mcneill on Wed Jul 06, 2022 7:09 pm

*********************************
Guide I'm following: https://learn.adafruit.com/welcome-to-a ... o/overview
I got the quote example to work and get time.
I am running circuitpyton 7.x on feather ESP32 S3

********************************

Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# adafruit_circuitpython_adafruitio usage with a CPython socket
import socket
import ssl
from random import randint
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
# source control.
# pylint: disable=no-name-in-module,wrong-import-order
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]


requests = adafruit_requests.Session(socket, ssl.create_default_context())
# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)

try:
    # Get the 'temperature' feed from Adafruit IO
    temperature_feed = io.get_feed("temperature")
except AdafruitIO_RequestError:
    # If no 'temperature' feed exists, create one
    temperature_feed = io.create_new_feed("temperature")

# Send random integer values to the feed
random_value = randint(0, 50)
print("Sending {0} to temperature feed...".format(random_value))
io.send_data(temperature_feed["key"], random_value)
print("Data sent!")

# Retrieve data value from the feed
print("Retrieving data from temperature feed...")
received_data = io.receive_data(temperature_feed["key"])
print("Data from temperature feed: ", received_data["value"])


*********************************
Guide I'm following: https://learn.adafruit.com/welcome-to-a ... o/overview
I got the quote example to work and get time.
I am running circuitpyton 7.x on feather ESP32 S3

********************************
Similar error on CS in
Other IOT codes like this feed example :

Code: Select all | TOGGLE FULL SIZE
# Feed to iot example not running 7-3-2022
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# Adafruit IO HTTP API - Feed Interactions
# Documentation: https://io.adafruit.com/api/docs/#feeds
# adafruit_circuitpython_adafruitio with an esp32spi_socket

import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
from adafruit_io.adafruit_io import IO_HTTP

# Add a secrets.py to your filesystem that
# has a dictionary called secrets with "ssid" and
# "password" keys with your WiFi credentials.
# DO NOT share that file or commit it into Git or other
# source control.
# pylint: disable=no-name-in-module,wrong-import-order
# pylint: disable=no-name-in-module,wrong-import-order
print("completed imports")
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

#  If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

print("Connecting to AP...")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets["ssid"], secrets["password"])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)
        continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)

# Create a new 'circuitpython' feed with a description
print("Creating new Adafruit IO feed...")
feed = io.create_new_feed("circuitpython", "a Adafruit IO CircuitPython feed")

# List a specified feed
# print("Retrieving new Adafruit IO feed...")
# specified_feed = io.get_feed("circuitpython")
print("specified_feed")

# Delete a specified feed by feed key
# print("Deleting feed...")
# io.delete_feed(specified_feed["key"])
print("done")


*******************************************
These give same error for CS_ using either the external or internal board versions. I can not determine which individual pins to try to define for S3 board usage. I will need I2C for intended pressure sensor project. https://learn.adafruit.com/lps35hw-wate ... ure-sensor. Help is greatly appreciated as I am at max frustration level currently.
Last edited by dastels on Wed Jul 06, 2022 7:45 pm, edited 1 time in total.
Reason: Fix code blocks

will22mcneill
 
Posts: 6
Joined: Thu Sep 10, 2020 5:40 pm

Re: circuitPhyton IOT error: no module named 'socket'

by dastels on Wed Jul 06, 2022 7:47 pm

Can you post the REPL output you're getting.

Dave

dastels
 
Posts: 10584
Joined: Tue Oct 20, 2015 3:22 pm

Re: circuitPhyton IOT error: no module named 'socket'

by neradoc on Wed Jul 06, 2022 8:43 pm

The network situation is a little complicated with CP. These are the wrong examples.
- The first one as mentioned in the comment is "usage with a CPython socket" (C-Python is desktop python, running on linux for example).
- The second one is for ESP32SPI, which is when using an external wifi ESP32 chip.

Here are 2 examples that are written for ESP32 native wifi:

https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO/blob/main/examples/adafruit_io_http/adafruit_io_simpletest.py
https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO/blob/main/examples/adafruit_io_mqtt/adafruit_io_simpletest_esp32s2.py

Basically if it uses "socketpool" it's for Circuitpython native wifi.

neradoc
 
Posts: 302
Joined: Wed Apr 27, 2016 2:38 pm

Re: circuitPhyton IOT error: no module named 'socket'

by will22mcneill on Thu Jul 07, 2022 12:47 am

thanks for the response I had not caught on to that naming detail at all.
I'll try on Thursday. Thanks again!!

will22mcneill
 
Posts: 6
Joined: Thu Sep 10, 2020 5:40 pm

Re: circuitPhyton IOT error: no module named 'socket'

by will22mcneill on Thu Jul 07, 2022 2:31 pm

Running the add create feed and get feed example.
in repl get "line 44, in <module>
Not ImplementedError:
so i need more help.

debug output (*******) replaced band words
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
Example using create_and_get_feed. Creates a new feed if it does not exist and sends to it, or
sends to an existing feed once it has been created.
"""
import ssl
import adafruit_requests
import socketpool
import wifi
import microcontroller
from adafruit_io.adafruit_io import IO_HTTP

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
# "password" keys with your WiFi credentials, and "aio_username" and "aio_key" keys with your
# Adafruit IO credentials, DO NOT share that file or commit it into Git or other
# source control.
# pylint: disable=no-name-in-module,wrong-import-order
try:
from secrets import secrets
except ImportError:
print(
"WiFi and Adafruit IO credentials are kept in secrets.py, please add them there!"
)
raise

# Connect to Wi-Fi using credentials from secrets.py
wifi.radio.connect(secrets["ssid"], secrets["password"])
print("Connected to {}!".format(secrets["ssid"]))
print("IP:", wifi.radio.ipv4_address)

pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())

# Obtain Adafruit IO credentials from secrets.py
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)

# Create temperature variable using the CPU temperature and print the current value.
temperature = microcontroller.cpu.temperature
print("Current CPU temperature: {0} C".format(temperature))

# Create and get feed.
io.send_data(io.create_and_get_feed("cpu-temperature-feed")["key"], temperature)
2022-07-07 10:06:09,812 - mu.modes.base:112(open) INFO: Connecting to REPL on port: COM7
2022-07-07 10:06:09,828 - mu.modes.base:130(open) INFO: Connected to REPL on port: COM7
2022-07-07 10:06:09,828 - mu.modes.base:503(add_repl) INFO: Started REPL on port: COM7
2022-07-07 10:06:09,828 - mu.modes.base:474(toggle_repl) INFO: Toggle REPL on.
2022-07-07 10:06:16,679 - mu.logic:1325(check_code) INFO: Checking code.
2022-07-07 10:06:16,679 - mu.logic:1335(check_code) INFO: {15: [{'line_no': 15, 'column': 88, 'message': 'Line too long (90 > 88 characters)', 'code': 'E501'}], 16: [{'line_no': 16, 'column': 88, 'message': 'Line too long (93 > 88 characters)', 'code': 'E501'}], 24: [{'line_no': 24, 'column': 88, 'message': 'Line too long (89 > 88 characters)', 'code': 'E501'}]}
2022-07-07 10:16:04,694 - mu.logic:1416(show_admin) INFO: Showing admin with logs from C:\Users\wilmc\AppData\Local\python\mu\Logs\mu.log
2022-07-07 10:16:04,694 - mu.virtual_environment:922(installed_packages) INFO: Discovering installed third party modules in venv.
2022-07-07 10:16:04,694 - mu.virtual_environment:114(run_blocking) INFO: About to run blocking C:\Users\wilmc\AppData\Local\python\mu\mu_venv-38-20220627-184109\scripts\pip.exe with args ['list', '--disable-pip-version-check'] and envvars {}
2022-07-07 10:16:11,124 - mu.virtual_environment:164(wait) DEBUG: Finished: True; exitStatus 0; exitCode 0
2022-07-07 10:16:11,124 - mu.virtual_environment:249(run) DEBUG: Process output: Package Version
----------------- -------
asttokens 2.0.5
backcall 0.2.0
bitstring 3.1.9
black 22.1.0
cffi 1.15.0
click 8.0.4
colorama 0.4.4
******* 36.0.1
decorator 5.1.1
ecdsa 0.17.0
entrypoints 0.4
esptool 3.2
executing 0.8.2
Flask 2.0.3
ipykernel 5.5.6
ipython 8.0.1
ipython-genutils 0.2.0
itsdangerous 2.1.0
0.18.1
Jinja2 3.0.3
jupyter-client 7.1.2
jupyter-core 4.9.2
MarkupSafe 2.1.0
matplotlib-inline 0.1.3
mypy-extensions 0.4.3
nest-asyncio 1.5.4
numpy 1.22.2
parso 0.8.3
pathspec 0.9.0
pgzero 1.2.1
pickleshare 0.7.5
pip 22.0.3
platformdirs 2.5.1
prompt-toolkit 3.0.28
pure-eval 0.2.2
pycparser 2.21
pygame 2.1.2
Pygments 2.11.2
pyserial 3.5
python-dateutil 2.8.2
pywin32 303
pyzmq 22.3.0
reedsolo 1.5.4
setuptools 60.9.3
six 1.16.0
stack-data 0.2.0
tomli 2.0.1
tornado 6.1
traitlets 5.1.1
typing_extensions 4.1.1
wcwidth 0.2.5
Werkzeug 2.0.3
wheel 0.37.1
2022-07-07 10:16:11,124 - mu.virtual_environment:931(installed_packages) INFO: []
2022-07-07 10:37:00,034 - mu.logic:1416(show_admin) INFO: Showing admin with logs from C:\Users\wilmc\AppData\Local\python\mu\Logs\mu.log
2022-07-07 10:37:00,034 - mu.virtual_environment:922(installed_packages) INFO: Discovering installed third party modules in venv.
2022-07-07 10:37:00,034 - mu.virtual_environment:114(run_blocking) INFO: About to run blocking C:\Users\wilmc\AppData\Local\python\mu\mu_venv-38-20220627-184109\scripts\pip.exe with args ['list', '--disable-pip-version-check'] and envvars {}
2022-07-07 10:37:00,616 - mu.virtual_environment:164(wait) DEBUG: Finished: True; exitStatus 0; exitCode 0
2022-07-07 10:37:00,616 - mu.virtual_environment:249(run) DEBUG: Process output: Package Version
----------------- -------
asttokens 2.0.5
backcall 0.2.0
bitstring 3.1.9
black 22.1.0
cffi 1.15.0
click 8.0.4
colorama 0.4.4
******** 36.0.1
decorator 5.1.1
ecdsa 0.17.0
entrypoints 0.4
esptool 3.2
executing 0.8.2
Flask 2.0.3
ipykernel 5.5.6
ipython 8.0.1
ipython-genutils 0.2.0
itsdangerous 2.1.0
****** 0.18.1
Jinja2 3.0.3
jupyter-client 7.1.2
jupyter-core 4.9.2
MarkupSafe 2.1.0
matplotlib-inline 0.1.3
mypy-extensions 0.4.3
nest-asyncio 1.5.4
numpy 1.22.2
parso 0.8.3
pathspec 0.9.0
pgzero 1.2.1
pickleshare 0.7.5
pip 22.0.3
platformdirs 2.5.1
prompt-toolkit 3.0.28
pure-eval 0.2.2
pycparser 2.21
pygame 2.1.2
Pygments 2.11.2
pyserial 3.5
python-dateutil 2.8.2
pywin32 303
pyzmq 22.3.0
reedsolo 1.5.4
setuptools 60.9.3
six 1.16.0
stack-data 0.2.0
tomli 2.0.1
tornado 6.1
traitlets 5.1.1
typing_extensions 4.1.1
wcwidth 0.2.5
Werkzeug 2.0.3
wheel 0.37.1
2022-07-07 10:37:00,616 - mu.virtual_environment:931(installed_packages) INFO: []



: []

will22mcneill
 
Posts: 6
Joined: Thu Sep 10, 2020 5:40 pm

Re: circuitPhyton IOT error: no module named 'socket'

by neradoc on Thu Jul 07, 2022 6:13 pm

It looks likes it's the microcontroller.cpu.temperature line. CPU temperature is not implemented on the S3 at present time.
It is not available in the stable version of the ESP-IDF used in Circuitpython at this time.
You would need an external temperature sensor if you want to monitor temperature.

neradoc
 
Posts: 302
Joined: Wed Apr 27, 2016 2:38 pm

Re: circuitPhyton IOT error: no module named 'socket'

by will22mcneill on Thu Jul 07, 2022 6:27 pm

Ok thanks. I'll remove it. It was just an easy, I thought, value to use to send to feed as test.
And let me say again how grateful I am for this help!!!

will22mcneill
 
Posts: 6
Joined: Thu Sep 10, 2020 5:40 pm

Re: circuitPhyton IOT error: no module named 'socket'

by will22mcneill on Fri Jul 08, 2022 6:37 pm

I commented out cpu temperature call, and then it fails for: for invalid Api key provided.
I verified my secret aio_key was being passed correctly, and regenerated new aio_key. Same error.

Adafruit_io Request Error: adafruit IO Error 401: request failed invalid API key provided.

So what can i try to do next?
Attachments
croped relp output.jpg
paint copy of the relp output
croped relp output.jpg (112.05 KiB) Viewed 81 times

will22mcneill
 
Posts: 6
Joined: Thu Sep 10, 2020 5:40 pm

Re: circuitPhyton IOT error: no module named 'socket'

by brubell on Mon Jul 11, 2022 11:18 am


brubell
 
Posts: 1701
Joined: Fri Jul 17, 2015 10:33 pm

Re: circuitPhyton IOT error: no module named 'socket'

by will22mcneill on Mon Jul 11, 2022 2:44 pm

I finally saw it. In my secret file I had : ' "secret_key" '
Once I removed the ' ' the code worked.

Thanks for all the help. My apologizes for not catching it on my own. I would have given up without the support. Greatly appreciated.

will22mcneill
 
Posts: 6
Joined: Thu Sep 10, 2020 5:40 pm

Please be positive and constructive with your questions and comments.