I just put my hands on RP Pico W to try it out but I hit the issue with the very first wifi test.
Tutorials say to do this:
import network
import socket
from time import sleep
from picozero import pico_temp_sensor, pico_led
import machine
so my pico lib folder looks like this when I imported all required packages:
However when try to run wifi test like this:
def connect():
#Connect to WLAN
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while wlan.isconnected() == False:
print('Waiting for connection...')
sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')
try:
connect()
except KeyboardInterrupt:
machine.reset()
it fails with following error:
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/network.py", line 8, in <module>
File "/lib/socket.py", line 42, in <module>
AttributeError: 'module' object has no attribute 'socket'
>>>
This is whole code, I skipped only ssid and password.
I cannot figure out what exactly is wrong here. I do not have any other files named the same as socket or so.
I took the example from RP foundation pages:
https://projects.raspberrypi.org/en/projects/get-started-pico-w/2
Related
I can use the nrf24l01 wireless module just fine with a Raspberry Pi Pico, but when I try to compile the same code on the Raspberry Pi Pico W, it fails to recognize the device. I am using this library, and I get this error:
Traceback (most recent call last):
File "<stdin>", line 31, in <module>
File "nrf24l01.py", line 78, in __init__
OSError: nRF24L01+ Hardware not responding
The boards are supposed to have the same footprint, so what is the difference here? How can I use these modules with the Pico W?
I am trying to open camera with the picamera module in my Raspberry pi B+ with has Raspbian 64 bit OS installed in it. I get this error:
Traceback (most recent call last):
File "/home/pi/Documents/hydroponics/scripts/picamera_test.py", line 1, in <module>
from picamera import PiCamera
File "/home/pi/.local/lib/python3.9/site-packages/picamera/__init__.py", line 72, in <module>
from picamera.exc import (
File "/home/pi/.local/lib/python3.9/site-packages/picamera/exc.py", line 41, in <module>
import picamera.mmal as mmal
File "/home/pi/.local/lib/python3.9/site-packages/picamera/mmal.py", line 49, in <module>
_lib = ct.CDLL('libmmal.so')
File "/usr/lib/python3.9/ctypes/__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libmmal.so: cannot open shared object file: No such file or directory
The camera is enabled (I tried to capture the camera with opencv and it worked).
I tried sudo rpi-update as well and it says that my firmware is already up to date.
Tried sudo apt update and sudo apt upgrade but none of them solve the above issue.
I tried sudo ldconfig -p | grep mmal as well and it outputs:
libmmal_vc_client.so (libc6) => /opt/vc/lib/libmmal_vc_client.so
libmmal_util.so (libc6) => /opt/vc/lib/libmmal_util.so
libmmal_core.so (libc6) => /opt/vc/lib/libmmal_core.so
libmmal_components.so (libc6) => /opt/vc/lib/libmmal_components.so
libmmal.so (libc6) => /opt/vc/lib/libmmal.so
Any suggestions on what I can do to solve this error? Thanks!
I just found out that picamera is still not supported for Raspbian 64 bit OS.
https://github.com/raspberrypi/firmware/issues/1558#issuecomment-983483179
So we could probably use libcamera (didn't try it yet) or opencv (tried and works fine)
I am following the getting started guide for the Google Coral USB Accelerator and even though I was able to trick the install.sh file to install for RPI4
https://twitter.com/hansamann/status/1154021771554766849
I cannot run the example with the image classification. When I run the sample, I get this:
python3 classify_image.py --model ~/Downloads/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --label ~/Downloads/inat_bird_labels.txt --image ~/Downloads/parrot.jpg
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/edgetpu/swig/edgetpu_cpp_wrapper.py", line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_edgetpu_cpp_wrapper', [dirname(__file__)])
File "/usr/lib/python3.7/imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_edgetpu_cpp_wrapper'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "classify_image.py", line 19, in <module>
from edgetpu.classification.engine import ClassificationEngine
File "/usr/local/lib/python3.7/dist-packages/edgetpu/classification/engine.py", line 17, in <module>
from edgetpu.basic.basic_engine import BasicEngine
File "/usr/local/lib/python3.7/dist-packages/edgetpu/basic/basic_engine.py", line 15, in <module>
from edgetpu.swig.edgetpu_cpp_wrapper import BasicEngine
File "/usr/local/lib/python3.7/dist-packages/edgetpu/swig/edgetpu_cpp_wrapper.py", line 28, in <module>
_edgetpu_cpp_wrapper = swig_import_helper()
File "/usr/local/lib/python3.7/dist-packages/edgetpu/swig/edgetpu_cpp_wrapper.py", line 20, in swig_import_helper
import _edgetpu_cpp_wrapper
ModuleNotFoundError: No module named '_edgetpu_cpp_wrapper'
Any idea whay I could try?
I had the same problem but with an older Rpi 3. This is the solution I used. I don't think it's a make or break to complete the project:
$ sudo cp _edgetpu_cpp_wrapper.cpython-35m-arm-linux-gnueabihf.so _edgetpu_cpp_wrapper.cpython-37m-arm-linux-gnueabihf.so
Can you go through : https://github.com/google-coral/edgetpu-platforms ?
This repository holds auxiliary platform-related material related to Google Coral Edge TPU. Here you can find precompiled images, shared libraries and patches for using the USB Edge TPU accelerator on additional platforms to the main supported ones.
For convenience Google has uploaded prebuilt images for Raspberry Pi Zero, Pi 3 and Pi 4. Simply write the image to an sd card and boot up your Pi. The images contain several examples that should work out of the box.
here is my script:
from email.mime.text import MIMEText
import smtplib
msg=MIMEText('hi, send by python.....','plain','utf-8')
from_addr='user#gmail.com'
passowrd='psw'
to_addr='user#gmail.com'
s=smtplib.SMTP('smtp.gmail.com',587)
s.login(from_addr,password)
s.sendmail(from_addr, [to_addr], msg.as_string())
when it is running, error occurs:
Traceback (most recent call last):
File "C:\Users\bicuilin\Desktop\begin.py", line 17, in <module>
s.login(from_addr, password)
File "C:\Users\bicuilin\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 696, in login
"SMTP AUTH extension not supported by server.")
smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.
I try to fix it. I add code below:
...
s.ehlo()
s.starttls()
s.login(from_addr, password)
s.sendmail(from_addr, [to_addr], msg.as_string())
s.quit()
here comes out error I really don't understand:
Traceback (most recent call last):
File "C:\Users\bicuilin\Desktop\begin.py", line 20, in <module>
s.login(from_addr, password)
File "C:\Users\bicuilin\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 729, in login
raise last_exception
File "C:\Users\bicuilin\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 720, in login
initial_response_ok=initial_response_ok)
File "C:\Users\bicuilin\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 641, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvK\n5.7.14 1h8JVCjH3EdlnG4ye0St7PIWFsYfjtuO_qovrt6r-spvSMGNbeCxbpXuo3HfqK535dgJy2\n5.7.14 Tjz1zrEZI8QqRc0GyXD2t3Xa0rj_MVHbzX5fM1f2zgbFyoP9YUbwCyaRD5guosxyv3HcS8\n5.7.14 fvB_ORP6_djncJPUwGw98BDCTo2pw3RSvgYHAvS_xO-T97Hw2z35g3AKPW9Bb5E9EcpAgg\n5.7.14 pewpsm0VngKqoxhYhtFwHBW_8s1ig> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 a67sm1686251qkc.24 - gsmtp')
You have to use SMTP_SSL class and it works (tested here). no need to starttls (won't work anyway)
from email.mime.text import MIMEText
import smtplib
msg=MIMEText('hi, send by python.....','plain','utf-8')
from_addr='user#gmail.com'
password='psw'
to_addr='user#gmail.com'
s=smtplib.SMTP_SSL('smtp.gmail.com')
s.login(from_addr,password)
s.sendmail(from_addr, [to_addr], msg.as_string())
Less Secure Apps - gmail
Had the same issue. after allow less secure apps at Gmail, got it working!
I am in the process of building a Tornado Web server which requires to perform some blocking tasks such as zipping video files, etc which are time consuming. Ideally, I would like to hand off these tasks
to a subprocess utility like Celery and inform the Client accordingly. So, I took this code from GitHub & modified it to get better understanding. I am using Ubuntu 12.04 LTS and here's what I have done so far:
Installed Tornado and working great on its own.
Installed RabbitMQ (apt-get install rabbitmq-server).
Installed Tornado Celery (downloaded and unzipped the tar file).
Executed python -m pip install tornado-celery
Borrowed 2 example python files from above Github Repo and modified it.
My Tasks snippet code (myTornadoTasks.py) is:
import os
import time
from datetime import datetime
from celery import Celery
from celery import task
celery = Celery("myTornadoTasks", broker="amqp://")
celery.conf.CELERY_RESULT_BACKEND = os.environ.get('CELERY_RESULT_BACKEND', 'amqp')
#celery.task
def add(x, y):
return int(x) + int(y)
..... some more code
#celery.task
def error(msg):
raise Exception(msg)
if __name__ == "__main__":
celery.start()
I start the tasks using celery worker -A myTornadoTasks &. Here everything works fine and I see 24 threads running.
My Tornado Celery snippet code (myTornadoCelery.py) is:
from tornado import gen
from tornado import ioloop
from tornado.web import asynchronous, RequestHandler, Application
import myTornadoTasks
import tcelery tcelery.setup_nonblocking_producer()
class AsyncHandler(RequestHandler):
#asynchronous
def get(self):
myTornadoTasks.sleep.apply_async(args=[3], callback=self.on_result)
def on_result(self, response):
self.write(str(response.result))
self.finish()
... some more code
application = Application([
(r"/async-sleep", AsyncHandler),
(r"/gen-async-sleep", GenAsyncHandler),
(r"/gen-async-sleep-add", GenMultipleAsyncHandler),
])
if __name__ == "__main__":
application.listen(8887)
ioloop.IOLoop.instance().start()
I start Tornado using python -m tcelery --app=myTornadoCelery --address=0.0.0.0
I get an error AttributeError: 'module' object has no attribute 'celery'
Questions:
What does the above error mean? What am I missing?
Did I miss any steps here? Where is RabbitMQ invoked?
How do I increase/decrease the number of Celery workers from 24?
Thanks.
Updated with Error:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/tcelery/__main__.py", line 62, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/tcelery/__main__.py", line 56, in main
cmd.execute_from_commandline()
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 309, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 469, in setup_app_from_commandline
self.app = self.find_app(app)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 489, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/usr/local/lib/python2.7/dist-packages/celery/app/utils.py", line 240, in find_app
found = sym.celery
AttributeError: 'module' object has no attribute 'celery'