OSError: [Errno 2] ENOENT

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Sonam Phuntsho
Posts: 6
Joined: Tue Aug 27, 2019 2:33 am

OSError: [Errno 2] ENOENT

Post by Sonam Phuntsho » Wed Aug 28, 2019 2:41 pm

Hi,

I am intending to convert the ascii.txt file into the hexadecimal and I used the following code (micropython) in Lopy4 which has ESP32;

import binascii
ascii = 'ascii.txt'
with open(ascii, 'rb') as f:
content = f.read()
data = binascii.hexlify(content)
print(data)

But I am getting the following error when I run the code

Traceback (most recent call last):
File "<stdin>", line 4, in <module>
OSError: [Errno 2] ENOENT
>
Pycom MicroPython 1.18.2.r6 [v1.8.6-849-a210e85] on 2019-05-13; LoPy4 with ESP32
Type "help()" for more information.
>>>

However, when I run the above code in the Pycharm IDE, I did get the result as attached which I feel I got the result.

Can anyone help me what did I do wrong in the Lopy4 which has ESP32 using micropython and how do I rectify the error shown above please.

Thank you
Capture.JPG
Capture.JPG (74.07 KiB) Viewed 169 times

User avatar
Roberthh
Posts: 1568
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: OSError: [Errno 2] ENOENT

Post by Roberthh » Wed Aug 28, 2019 4:51 pm

ENOENT means file not found. What is the size of ascii.txt? The way you code it has to fit in RAM, and the converted data too.

Sonam Phuntsho
Posts: 6
Joined: Tue Aug 27, 2019 2:33 am

Re: OSError: [Errno 2] ENOENT

Post by Sonam Phuntsho » Thu Aug 29, 2019 3:51 am

The file ascii.txt is only 1Kb and it was located in the same folder. In fact I did not upload the main.py code as well as the ascii.txt in the flash. Is it because of that?

Thank you

User avatar
Roberthh
Posts: 1568
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: OSError: [Errno 2] ENOENT

Post by Roberthh » Thu Aug 29, 2019 6:01 am

Ok. You get the ENOENt error because there is no main.py on the board. You can ignore that error. To run your code, assuming it is in a file called to_hex.py, you have to type at the REPL:

import to_hex

you may also run that from a main.py file, which is executed at every boot.

Sonam Phuntsho
Posts: 6
Joined: Tue Aug 27, 2019 2:33 am

Re: OSError: [Errno 2] ENOENT

Post by Sonam Phuntsho » Wed Sep 11, 2019 2:24 am

Thank you @ roberthh. (Apology for the long gap and again bringing this topic) I could upload the main.py and boot.py with ascii.txt file to the lopy4 flash and the program could run and i can see the print executed.

My code below:
i

Code: Select all

mport binascii
import struct

ascii = 'SIGN.txt'
with open(ascii, 'rb') as f:
    content = f.read()
    data = binascii.hexlify(content)
print(binascii.hexlify(content))
print(content)
print(data)
l = len(data)
print (l)
hex_string = binascii.unhexlify(data)
print (hex_string)
print (len (hex_string))

for l in range (0, l, 10):
    package = data[1:l+10]
    print (package)
 
Actually I intend to send the package with some delay through lora from lopy4 and retrieve the package in lora gateway. I am trying to struct.pack the package and send with defined socket. I am new to the micropython in fact, Could you help me guide in these?

Thank you in advance.

User avatar
Roberthh
Posts: 1568
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: OSError: [Errno 2] ENOENT

Post by Roberthh » Wed Sep 11, 2019 5:56 am

First of all, for anything related to LoPy4 you should better ask at the Pycom forum https://forum.pycom.io/.
Besides that, for sending data with Lora, you do not have to convert it to ASCII-Hex. In fact, due to the low Lora data rate, it would make things worse. The transmission time is doubled. For examples on using Lora, you can follow the documenattaion, which is linked on the Pycom forum webs site..

Sonam Phuntsho
Posts: 6
Joined: Tue Aug 27, 2019 2:33 am

Re: OSError: [Errno 2] ENOENT

Post by Sonam Phuntsho » Wed Sep 11, 2019 6:44 am

Thank you for the information @ roberthh. :)

Post Reply