epl70

SDS011 Sensor auslesen

Feb 12th, 2017
1,310
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. WDIR=.
  4.  
  5. stty -F /dev/ttyUSB0 9600 raw
  6.  
  7. INPUT=$(od --endian=big -x -N10 < /dev/ttyUSB0|head -n 1|cut -f2-10 -d" ");
  8.  
  9. #Ausgabe
  10. echo $INPUT
  11. echo " "
  12.  
  13. FIRST4BYTES=$(echo $INPUT|cut -b1-4);
  14. echo $FIRST4BYTES
  15.  
  16. if [ "$FIRST4BYTES" = "aac0" ]; then
  17.   echo "check for correct intro characters: ok"
  18.   logger "check for correct intro characters: ok"
  19. else
  20.   echo "incorrect sequence, exiting"
  21.   logger "incorrect sequence, exiting"
  22.   exit;
  23. fi
  24.  
  25. PPM25LOW=$(echo $INPUT|cut -f2 -d " "|cut -b1-2);
  26. PPM25HIGH=$(echo $INPUT|cut -f2 -d " "|cut -b3-4);
  27.  
  28. PPM10LOW=$(echo $INPUT|cut -f3 -d " "|cut -b1-2);
  29. PPM10HIGH=$(echo $INPUT|cut -f3 -d " "|cut -b3-4);
  30.  
  31. #zu Dezimal konvertieren
  32. PPM25LOWDEC=$( echo $((0x$PPM25LOW)) );
  33. PPM25HIGHDEC=$( echo $((0x$PPM25HIGH)) );
  34.  
  35. PPM10LOWDEC=$( echo $((0x$PPM10LOW)) );
  36. PPM10HIGHDEC=$( echo $((0x$PPM10HIGH)) );
  37.  
  38. PPM25=$(echo "scale=1;((( $PPM25HIGHDEC * 256 ) + $PPM25LOWDEC ) / 10 ) "|bc -l );
  39. PPM10=$(echo "scale=1;((( $PPM10HIGHDEC * 256 ) + $PPM10LOWDEC ) / 10 ) "|bc -l );
  40.  
  41. logger "Feinstaub PPM25: $PPM25"
  42. logger "Feinstaub PPM10: $PPM10"
  43.  
  44. echo "Feinstaub PPM25: $PPM25"
  45. echo "Feinstaub PPM10: $PPM10"
  46.  
  47. echo $PPM25 >> $WDIR/etc/ppm25.txt
  48. echo $PPM10 >> $WDIR/etc/ppm10.txt
  49.  
  50. # wget "http://data.sparkfun.com/input/[publicKey]?private_key=[privateKey]&pm10=[value]&pm25=[value]"
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×