Sending python file from STM32 to XBEE

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
hiharsh
Posts: 13
Joined: Sun Jan 31, 2021 4:31 pm

Sending python file from STM32 to XBEE

Post by hiharsh » Sun Jan 31, 2021 4:41 pm

Hi,
I am trying to send simple.py and robust.py from the STM32 board to the XBee module under micropython mode using a serial port.
I found that when the data is received on the XBee the indentation is corrupted. Hence, Micropython on XBee can't run the python file transferred.
Is there a way to transfer the python file as it is where it retains indentation using STM32 over serial?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Sending python file from STM32 to XBEE

Post by jimmo » Mon Feb 08, 2021 6:56 am

hiharsh wrote:
Sun Jan 31, 2021 4:41 pm
Is there a way to transfer the python file as it is where it retains indentation using STM32 over serial?
Can you provide more information about how you're transferring the file? Maybe post your code or commands?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Sending python file from STM32 to XBEE

Post by dhylands » Mon Feb 08, 2021 7:00 pm

Does pyboard.py work with the XBee? If so, I have a little script that can generate python source files which might work for you.

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

Re: Sending python file from STM32 to XBEE

Post by Roberthh » Mon Feb 08, 2021 7:12 pm

Does pyboard.py work with the XBee?
Yes

hiharsh
Posts: 13
Joined: Sun Jan 31, 2021 4:31 pm

Re: Sending python file from STM32 to XBEE

Post by hiharsh » Tue Feb 09, 2021 3:23 pm

I have an STM32 microcontroller that is connected with XBee over serial port.
I need to send MQTT library files which are simple.py and robust.py to XBee flash.

Step 1.Store all the contents of the python files to an array. (I also tried storing each line to a string)
Step 2. Open the serial port, park XBee under micropython mode, and invoke f.write () under which write the data line by line with all the spaces and indentation.
Step3. The file gets transferred but the indentation gets corrupted for some of the blocks in the python file.

I am stuck on this for the last 2 weeks.
If needed I can submit the code and the output file.

I would appreciate your help.

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

Re: Sending python file from STM32 to XBEE

Post by Roberthh » Tue Feb 09, 2021 4:04 pm

So you want to send two python scripts to the XBEE. And you want top send them from a STM32 micro. May I ask you why you do not use a PC to send the file over USB to the XBEE? That is the most simple version, either using the XCTU tool or pyboard.py.
With respect to the messed up indentation: did you check that the simple.py and robust.py have not tab and space characters mixed for indentation? That is always a source of trouble. Otherwise, characters may get lost on a serial link without flow control. But that would not happend only for whitespace characters like tab and space.
And yes: Please proved the code and the output file. Use the code button or the marks to enclose it. Or just embed it into your post as a zip file.

hiharsh
Posts: 13
Joined: Sun Jan 31, 2021 4:31 pm

Re: Sending python file from STM32 to XBEE

Post by hiharsh » Tue Feb 09, 2021 7:09 pm

Yes, I want to send two python file from STM32 to XBee.
I have XBee part of my complete embedded solution with STM micro attached to it via a serial port. I can't afford to open XBee when it comes from a factory and connect XCTU or any other board.

Yes, I have checked those files and everything on those files looks correct from space/tab/indentation point of view. I loaded the same files using XCTU for verification and use it from XBee.

I will try to upload the snippet of the code and error if possible by tomorrow.

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

Re: Sending python file from STM32 to XBEE

Post by Roberthh » Tue Feb 09, 2021 7:36 pm

if you send the files line by line, did you add a delay after each line? If at the XBEE side uart.readline() is used, it requires some time to process the data.

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

Re: Sending python file from STM32 to XBEE

Post by Roberthh » Tue Feb 09, 2021 7:40 pm

Another question: does the stm32 have an interface to the outside world?

hiharsh
Posts: 13
Joined: Sun Jan 31, 2021 4:31 pm

Re: Sending python file from STM32 to XBEE

Post by hiharsh » Tue Feb 09, 2021 7:58 pm

When I send line by line, I have added delay before sending each line. STM32 doesn't have an interface to the outside world. How could have that helped?

Post Reply