Apnea Board Forum - CPAP | Sleep Apnea
Linux Downloadscript for FlashAir V1 and Airsense 10 - Printable Version

+- Apnea Board Forum - CPAP | Sleep Apnea (https://www.apneaboard.com/forums)
+-- Forum: Public Area (https://www.apneaboard.com/forums/Forum-Public-Area)
+--- Forum: Software Support Forum (https://www.apneaboard.com/forums/Forum-Software-Support-Forum)
+--- Thread: Linux Downloadscript for FlashAir V1 and Airsense 10 (/Thread-Linux-Downloadscript-for-FlashAir-V1-and-Airsense-10)



Linux Downloadscript for FlashAir V1 and Airsense 10 - BobbyB - 01-18-2022

Hi, unfotunatly i bought an old FlashAir V1. It does not support long filenames and you are only able to download files via webbrowser. So i recommend buying some other card or at least a W-03.

Anyway i wrote a linux shell script to autodownload the session data from the Airsense 10. Unfortunatly it does not work with other machines.

Set your card to stationmode by adding "APPMODE=5" to your /SD_WLAN/CONFIG.

Code:
#!/bin/bash
# IP of your FlashAirCard
flashairip=192.168.1.41
# Folder you want to copy the SD-Files to
destinationdir=/destinationfolder



datadir=DATALOG/
filename=website.txt
filename2=doc.txt
declare -i y
yesterday=$(date -d "yesterday" '+%Y%m%d')
mkdir -p $destinationdir$datadir$yesterday
wget -np -q --output-document $filename http://$flashairip/$datadir$yesterday/
mapfile -t arr < $filename
for i in "${arr[@]}"
do
   if [[ "$i" =~ wlansd\[.*\]=.* ]]; then
    IFS="\"" read -a line <<< $i
    IFS="," read -a line <<< ${line[1]}
    IFS="." read -a ending <<< ${line[1]}              # you could get Time and Date by shifting and masking line 4 and 5. See below.
    wget -np -q --output-document $filename2 http://$flashairip/$datadir$yesterday/${line[1]}
    if [[ ${ending[1]} == "EDF" ]]; then
        ident=$(head -c 25 $filename2 | cut -c 22-)
        filedate=$(head -c 176 $filename2 | cut -c 169-)
        filetime=$(head -c 184 $filename2 | cut -c 177-)
        IFS="." read -a filetime <<< $filetime
        IFS="." read -a filedate <<< $filedate
        y=2000+filedate[2]
        case $ident in
        597B)
            sufix="CSL"
            ;;
        B0A2)
            sufix="EVE"
            ;;
        54DC)
            sufix="BRP"
            ;;
        85B7)
            sufix="PLD"
            ;;
        C580)
            sufix="SAD"
            ;;
        *)
            echo "Error - Could not recognize Datatype"
            ;;
        esac
    fi
    newname=$y${filedate[1]}${filedate[0]}_${filetime[0]}${filetime[1]}${filetime[2]}_$sufix.${ending[1],,}
    mv $filename2 $destinationdir$datadir$yesterday/$newname
   fi
done
wget -np -q --output-document ${destinationdir}STR.edf http://$flashairip/STR.edf
rm $filename

In case want to use the filedate and time:
Code:
     declare -i j y m d h m i s
    j=${line[4]}
    y=$(((($j & 0xfe00 )) >> 9 ))+1980
    m=$(((($j & 0x1e0 )) >> 5 ))
    d=$(((($j & 0x1f ))))
    j=${line[5]}
    h=$(((($j & 0xf800)) >> 11 ))
    mi=$(((($j & 0x7e0 )) >> 5 ))
    s=$(((($j & 0x1f)) << 1))
    printf -v newname "%04d%02d%02d_%02d%02d%02d_%02d.%s" $y $m $d $h $mi $s $k ${ending[1]}
Hope my script is not to dirty (please feel free to improve it).

Best wishes and be safe.


RE: Linux Downloadscript for FlashAir V1 and Airsense 10 - Crimson Nape - 01-18-2022

Nice workaround.  That's one way to make lemonade out of a lemon. Thank you for sharing the code.

Thanks