Can't write properly on SD



  • Hey guys! so that's my code....

    if not lora.has_joined():
            try:
                if sd != None:
                    print("SAVED!!!")
                    pycom.rgbled(0xfd6a02)
                    time.sleep(2)
                    with open('/sd/' + LOG_FILENAME, 'a') as f:
                        f.write("banana")
                        #f.write(bytes2send)
                        print("Printei isto!")
                    print("Passei aqui!")
            except Exception as e:
                print(str(e))
    

    the problem is... if i write only the string, the string is written no flaws!
    but when i try to write the bytearray and the string, he doesn't write the string no more and only numbers appear
    can someone explain this?

    Thank you in advance!



  • @morrison You should convert that to a printable version before writing, e.g. either with ubinascii.bin2hex(bytes2send)) or as repr(bytes2send)



  • I'm opening the SD card via usb bytes2send is a byte array with values for example
    bytes2send = bytearray(b'\x00@\xb3\xbd\x00 O>\x00\xa0v?\xef\xf6<\xc1W~\x98@x\x01\xb5\x0b\x00\x00\x07C\x00\x00\xfeB\xee\x03/')



  • @morrison What are the contents of bytes2send? How do you check/view your log file? You may want use hexdump or an equivalent tool to see what are the actual contents of the file. If you just cat the file and it contains a CR for instance, you might not see everything...


Log in to reply
 

Pycom on Twitter