5

I was trying to transfer a 50 MB file to my Raspberry Pi 3 via samba and I noticed that after few seconds the transfer slows down until it stops, same thing via scp. It starts but after few seconds (5-7) the speed drops. I'm running the latest Raspbian jessie.

This is the dmesg output:

[    4.272062] usbcore: registered new interface driver brcmfmac
[    4.408506] brcmfmac: brcmf_c_preinit_dcmds: Firmware version = wl0: May 27 2016 00:13:38 version 7.45.41.26 (r640327) FWID 01-df77e4a7
[    4.418558] cfg80211: World regulatory domain updated:
[    4.418584] cfg80211:  DFS Master region: unset
[    4.418593] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)
[    4.418608] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (N/A, 2000 mBm), (N/A)
[    4.418621] cfg80211:   (2457000 KHz - 2482000 KHz @ 40000 KHz), (N/A, 2000 mBm), (N/A)
[    4.418633] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (N/A, 2000 mBm), (N/A)
[    4.418647] cfg80211:   (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (N/A)
[    4.418661] cfg80211:   (5250000 KHz - 5330000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (0 s)
[    4.418674] cfg80211:   (5490000 KHz - 5730000 KHz @ 160000 KHz), (N/A, 2000 mBm), (0 s)
[    4.418686] cfg80211:   (5735000 KHz - 5835000 KHz @ 80000 KHz), (N/A, 2000 mBm), (N/A)
[    4.418698] cfg80211:   (57240000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 0 mBm), (N/A)
[    4.443235] brcmfmac: brcmf_cfg80211_reg_notifier: not a ISO3166 code
[    5.438938] brcmfmac: brcmf_add_if: ERROR: netdev:wlan0 already exists
[    5.438949] brcmfmac: brcmf_add_if: ignore IF event
[    5.443389] brcmfmac: power management disabled
[    5.962063] cfg80211: Regulatory domain changed to country: IT
[    5.962079] cfg80211:  DFS Master region: ETSI
[    5.962085] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)
[    5.962093] cfg80211:   (2402000 KHz - 2482000 KHz @ 40000 KHz), (N/A, 2000 mBm), (N/A)
[    5.962101] cfg80211:   (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (N/A)
[    5.962109] cfg80211:   (5250000 KHz - 5330000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (0 s)
[    5.962115] cfg80211:   (5490000 KHz - 5710000 KHz @ 160000 KHz), (N/A, 2700 mBm), (0 s)
[    5.962121] cfg80211:   (57000000 KHz - 66000000 KHz @ 2160000 KHz), (N/A, 4000 mBm), (N/A)

And from iwconfig wlan0:

wlan0     IEEE 802.11bgn  ESSID:"Name"  
          Mode:Managed  Frequency:2.437 GHz  Access Point: XX:XX:XX:XX:XX:XX  
          Bit Rate=72.2 Mb/s   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality=70/70  Signal level=-36 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:540  Invalid misc:0   Missed beacon:0

Could be a driver issue? Router channel? What does Tx excessive retries:540 mean, too?

Update: ifconfig wlan0 reveals that i'm having several RX packets dropped (about 10%, even though disabling power management improved a bit).

In fact, sending data FROM the pi looks reasonably fast, sending TO the Pi is very slow (1-1.5 MB/s).

  • I assume it's probably because you're being limited by SD disk write speed. Unless you're trying to write to a different attached USB drive? I don't know what speeds are but I assume network transfer speed is likely way faster than the write operation to an SD disk. – dbmitch Oct 22 '16 at 19:24
  • It shouldn't, it's a 32 gb samsung evo micro sd card. Looking at wavemon via ssh it seems that the raspberry pi itself hangs, making the connection very unstable. – Matteo Oct 22 '16 at 19:42
  • Your problem is probably nothing to do with the Pi. This is likely a normal network response to network errors. – Milliways Oct 23 '16 at 0:23
  • @Milliways since you are saying the that it's not the pi, which network errors are you talking about? – Matteo Oct 24 '16 at 5:58
  • 1
    Could it be a power issue? WLAN uses quite a bit of power, there might be not enough left for the Pi, depending on how much the micro USB adapter can supply. – LeonG Mar 7 '17 at 20:32
0

Even I also face similar problem to send an large image file in wife network. Possible solution which worked for me is to compress the image using inflate method and divide the whole image into smaller chunk of packet in the client side and send it to the server.

From the server side collect the smaller chunks of packet and reconstruct the compressed image format. Finally decompress the image using deflate method.

Client Code:

#!/usr/bin/python
# TCP client example
import socket
import time
from picamera import PiCamera
from time import sleep

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("10.14.80.92", 5005))
k = ' '
size = 1024

import zlib
import base64

def decode_base64_and_inflate( b64string ):
    decoded_data = base64.b64decode( b64string )
    return zlib.decompress( decoded_data , -15)

def deflate_and_base64_encode( string_val ):
    zlibbed_str = zlib.compress( string_val )
    compressed_string = zlibbed_str[2:-4]
    return base64.b64encode( compressed_string )

while(1):    
    camera = PiCamera()
    camera.resolution = (1024,786)
    camera.start_preview()
    sleep(5)
    camera.capture("/home/pi/Imageprocessing/image.jpg")
    camera.stop_preview()
    camera.close()
    fname = 'image.jpg'
    img = open(fname,'rb')

    strng = img.read()
    strng = deflate_and_base64_encode(strng)
    start = 0
    stop = 20000
    while True:
            s = strng[start:stop]
            if not s:
                break
            start += 20000
            stop += 20000
            client_socket.send(strng)
            print(len(strng))
    img.close()
    print ("Data sent successfully")
    exit()



#    client_socket.send(fname.encode())
    fname = 'documents/'+fname
    fp = open(fname,'wb')
    strng = bytearray()
    while True:
        s = client_socket.recv(20000)
        if not s:
            break
        strng.extend(s)
    print(len(strng))
    strng = decode_base64_and_inflate(strng)
    fp.write(strng)
    fp.close()
    print ("Data Received successfully")
    exit()

Server Code:

import socket
import time
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("10.145.202.219", 5005))
server_socket.listen(5)
import os

import zlib
import base64

def decode_base64_and_inflate( b64string ):
    decoded_data = base64.b64decode( b64string )
    return zlib.decompress( decoded_data , -15)

def deflate_and_base64_encode( string_val ):
    zlibbed_str = zlib.compress( string_val )
    compressed_string = zlibbed_str[2:-4]
    return base64.b64encode( compressed_string )

client_socket, address = server_socket.accept()
print ("Conencted to - ",address,"\n")

while (1):    
    fname = 'documents/image.jpg'
    fp = open(fname,'wb')
    strng = bytearray()
    while True:
        s = client_socket.recv(20000)
        if not s:
            break
        strng.extend(s)

    strng = decode_base64_and_inflate(strng)
    fp.write(strng)
    fp.close()
    print ("Data Received successfully")




    exit()

Hope this will work. Cheers!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.