OSError: the requested operation is not possible Pysense

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
oa15968
Posts: 1
Joined: Thu Aug 02, 2018 10:25 am

OSError: the requested operation is not possible Pysense

Post by oa15968 » Thu Aug 02, 2018 10:28 am

Hello,

I have tried this code yesterday to connect to the WiFi and print the data and it worked. I ran again today but it's not working.

File 1 #main.py

# See https://docs.pycom.io for more information regarding library specifics
from boot import *
import time
import machine
from pysense import Pysense
from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE

if __name__ == "__main__":

wifi_ssid = 'OnePlus5'
wifi_pass = '123456oa'
con = ConnectionIoT(wifi_ssid,wifi_pass)

if con==True:
print ("Connection established")

py = Pysense()
mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
si = SI7006A20(py)
lt = LTR329ALS01(py)
li = LIS2HH12(py)

print("MPL3115A2 temperature: " + str(mp.temperature()))
print("Altitude: " + str(mp.altitude()))
mpp = MPL3115A2(py,mode=PRESSURE) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters
print("Pressure: " + str(mpp.pressure()))

print("Temperature: " + str(si.temperature())+ " deg C and Relative Humidity: " + str(si.humidity()) + " %RH")
print("Dew point: "+ str(si.dew_point()) + " deg C")
t_ambient = 24.4
print("Humidity Ambient for " + str(t_ambient) + " deg C is " + str(si.humid_ambient(t_ambient)) + "%RH")

print("Light (channel Blue lux, channel Red lux): " + str(lt.light()))

print("Acceleration: " + str(li.acceleration()))
print("Roll: " + str(li.roll()))
print("Pitch: " + str(li.pitch()))

print("Battery voltage: " + str(py.read_battery_voltage()))

file2: boot.py

import machine
from network import WLAN
wlan = WLAN() # get current object, without changing the mode

print ("Connecting....")
def ConnectionIoT(ssid,passwifi):
if machine.reset_cause() != machine.SOFT_RESET:

nets = wlan.scan()
for net in nets:
if net.ssid == ssid:
print('Network found!')
wlan.connect(ssid, auth=(WLAN.WPA2, passwifi), timeout=5000)
while not wlan.isconnected():
machine.idle() # save power while waiting
print('WLAN connection succeeded!')
return True
else:
print ('not connected')
return False

I am getting the following error:

Traceback (most recent call last):
File "<stdin>", line 16, in <module>
File "boot.py", line 9, in ConnectionIoT
OSError: the requested operation is not possible

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: OSError: the requested operation is not possible Pysense

Post by pythoncoder » Fri Aug 03, 2018 8:34 am

What platform are you running on?

In general it's bad practice to put code in boot.py. It simplifies debugging if you minimise main.py too. Put your code into your own module(s) e.g. mymodule.py. Then you can test it by issuing

Code: Select all

>>> import mymodule
When it's working you can make it run automatically by editing main.py to read

Code: Select all

import mymodule
Even my biggest projects have a one-line main.py.

Making those changes won't necessarily fix your problem but it will make it easier to locate.
Peter Hinch
Index to my micropython libraries.

Post Reply