ESP8266_write to external file_Micropython

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
samerou
Posts: 38
Joined: Mon Feb 11, 2019 12:51 pm

ESP8266_write to external file_Micropython

Post by samerou » Tue Mar 19, 2019 3:04 pm

Hello , I'm still new with Micropython and I'm trying to find solution for every problem that can face but now I'm confused in some points
Now , I created a code that allows me to show a get values from sensors(String then convert it to Int and send it to database) thingspeak but what I'm trying to do is to get this data into an external file (TXT) or another type

So is there a way to write data into an external file located in PC ??
I found this code which allows me to write data into file located in ESP8266

Code: Select all

with open(myfile, 'w') as output: 
	output.write(class_instance.method())
thank you in advance and have a nice day

cefn
Posts: 230
Joined: Tue Aug 09, 2016 10:58 am

Re: ESP8266_write to external file_Micropython

Post by cefn » Fri Mar 22, 2019 10:46 am

You can put the data into a file on the ESP8266 and then copy the file to the PC.

I commonly use Adafruit's AMPY tool for this but RShell has support for file copying too

AMPY https://learn.adafruit.com/micropython- ... stall-ampy

RSHELL https://github.com/dhylands/rshell

Can you explain what you are trying to achieve and why writing to the ESP8266 wouldn't be appropriate?

samerou
Posts: 38
Joined: Mon Feb 11, 2019 12:51 pm

Re: ESP8266_write to external file_Micropython

Post by samerou » Sat Mar 23, 2019 10:48 pm

cefn wrote:
Fri Mar 22, 2019 10:46 am
You can put the data into a file on the ESP8266 and then copy the file to the PC.

I commonly use Adafruit's AMPY tool for this but RShell has support for file copying too

AMPY https://learn.adafruit.com/micropython- ... stall-ampy

RSHELL https://github.com/dhylands/rshell

Can you explain what you are trying to achieve and why writing to the ESP8266 wouldn't be appropriate?

Thank you for answering,

I can't keep writing on esp8266 because I will consume all the remaining memorie because I have data that I need to transfer every 1 sec or 2 to be analyze in the server. (data are values from sensor)
What I'm trying to do is to write in to an external file then transfer it to server or transfer what is inside there.

But if you have suggestion feel free to share it :D

Thank you in advance

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

Re: ESP8266_write to external file_Micropython

Post by Roberthh » Sun Mar 24, 2019 7:11 am

If you can connect the server permanently, you can also send the sensor data directly to the server and store them at the server.

samerou
Posts: 38
Joined: Mon Feb 11, 2019 12:51 pm

Re: ESP8266_write to external file_Micropython

Post by samerou » Sun Mar 24, 2019 8:52 am

Roberthh wrote:
Sun Mar 24, 2019 7:11 am
If you can connect the server permanently, you can also send the sensor data directly to the server and store them at the server.
Yes, I know but what kind of server that allows me to send data on it which mean create table there with all values from sensor.

Ps: things peak , cloud4rpi, dweet don't respond to my needs

What I need is server that :
can accept values every 1 or 2 sec with out freez.
Have the ability to let multiple users connect on it and send and receive data every 1 or 2 sec

cefn
Posts: 230
Joined: Tue Aug 09, 2016 10:58 am

Re: ESP8266_write to external file_Micropython

Post by cefn » Sun Mar 24, 2019 5:29 pm

Have you considered just using a socket server you've built yourself to get the data out of the ESP8266. Once you've sent the data to a CPython environment you should be able to transfer it to any database or service you want. There's bound to be a Cpython library to suit.

I've recently been exploring the use of uasyncio to work with clients and servers which have other tasks to do alongside sending or receiving bytes over sockets. https://github.com/peterhinch/micropyth ... ent_server

However, if your device only has the one task - to gather data and send it, you can use even simpler logic, based on 'blocking' sockets by following... https://realpython.com/python-sockets/# ... and-server but using the Micropython socket library at https://docs.micropython.org/en/latest/ ... ocket.html

It's still hard to fully answer your question, though, as we don't know what you're trying to do. All we know is how you're trying to do it and that it doesn't work.
Give some context: Describe why you are having that problem, not only the specific details of the problem. For example, instead of asking how to convert from file format A to file format B using program C, say something about your ultimate objective. For example, explain why you need file format B in the first place. That way, another user may be able to suggest a better way to reach your goal.
https://www.biostars.org/p/75548/

Post Reply