28.2.17

Python - der Einstieg

Ich muss einige Stringmanipulationen vornehmen und einen UTC Timestamp umrechnen.

Da wäre zunächst einmal split, um einen String aufzusplitten

string="das ist ein test"
s=string.split() # splittet anhand des Leerzeichens (default)
for words in string:
       print words

Dann eine Art Substring

timestamp_orig="1389022616940757"
timestamp=int(timestamp_orig[0:10])
print(timestamp)
'1389022616'

Und diesen Timestamp dann schön ausgeben:
import date
import datetime
print(datetime.datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'))


25.2.17

Arduino 433 MHZ Intertechno Funksteckdosen

http://www.rlobsiger.ch/jetzt-wirds-richtig-hell.html


Bibliothek importieren
Beispiel ausführen ShowReceivedCode


Ausgabe:
Addr 15821022 unit 1 off, period: 261us.
Addr 15821022 unit 2 off, period: 261us.
Addr 15821022 unit 0 on, period: 261us.
Addr 15821022 unit 1 on, period: 261us.
Addr 15821022 unit 1 off, period: 261us.
Addr 15821022 unit 0 off, period: 261us.
Addr 15821022 unit 2 off, period: 261us.


Ist nicht kompatibel zu den anderen Handsendern!

Billig Handsender aus China:

Diese Bibliothek einbinden. Beispiel ReceiveDemo_Advances und es gibt diese Ausgabe:

Decimal: 1393667 (24Bit) Binary: 000101010100010000000011 Tri-State: 0FFFF0F00001 PulseLength: 470 microseconds Protocol: 1
Raw data: 14596,468,1432,464,1432,464,1428,1436,484,472,1428,1448,476,484,1412,1452,468,488,1412,1444,476,480,1420,476,1420,480,1416,1444,476,480,1420,476,1420,476,1420,480,1420,472,1420,480,1420,476,1420,476,1420,1440,484,1440,484,



13.2.17

Mails von zu Hause verschicken über Postfix

Hier eine super Anleitung, mit der man Postfix so konfigurieren kann, dass er einen anderen Mailserver (z.B. den eigenen) als Relay mit SASL-Auth. nimmt.


Kurzform:
echo [mailrelay.domain.com] [username]:[password] > /etc/postfix/relay_password
postmap hash:/etc/postfix/relay_password
  

postfix/main.cf:
mynetworks_style = [host/subnet]

relayhost = [mailrelay.domain.com]
smtp_sasl_password_maps=hash:/etc/postfix/relay_password
smtp_sasl_auth_enable=yes
smtp_sasl_security_options = noanonymous

Bash - viele viele Nutzer anlegen

#!/bin/bash

GROUP="GRUPPE"
PASSWORD="Passwort"
HOME_BASE="/home/"
USER="Benutzername"

for ((i=1;i<25;i++))
do
  echo "Lege Benutzer ${USER}${i} an"
  /usr/sbin/useradd -g ${GROUP} -m -d "${HOME_BASE}${USER}${i}" "${USER}${i}"
echo "${USER}${i}":"${PASSWORD}${i}" | chpasswd
done.

11.2.17

Mit dem Raspberry den Arduino steuern

Hintergrund:
Ich habe ein Codeschloss installiert und mit einem Arduino verbunden.
Nun soll ein PI diesen ansteuern.
Nach etlichen Versuchen mit Python Scripten, nun erst einmal ein sehr einfaches Shell Script, mit dem ich das Menü des Arduino aufrufen kann.
Verbunden ist der Arduino ganz normal per USB mit dem Raspberry.

#!/bin/bash
SERIAL="/dev/ttyACM0"
while true
do
    read line
    echo $line > $SERIAL
    sleep 2
....
    cat $SERIAL
done
Ausgabe:

***** MENU ****
<enter> -> print this menu
  1     -> learn a code / paste csv-list of codes
  2     -> delete a code
  3     -> display all codes
  7     -> reset tamper flag & reboot
  8     -> save all codes to eeprom
  999   -> delete ALL codes in eeprom
Notes: Name entries max 9 characters.
       Action entries 1 for open, 0 for close.
To be continued...

4.2.17

Wiegand - next try - mit Arduino

Anhand dieser klasse Anleitung hatte ich endlich Erfolg.
Ich konnte den Code der RFIDs auslesen.
Zuvor war ich mit Pidoorman und dem Raspberry leider gescheitert.
Die Codes wurden nicht erkannt.

Nun aber mit dem Arduino.

Schaltung:

D0 Wiegand an D2 Arduino (D0 am DK-2872 => Blau)
D1 Wiegand an D3 Arduino (D1 => Gelb)
GND Wiegand and GND Arduino (GND => Schwarz)

Software von der o.a. Webseite.
HandleCodes.ino
/*
  Wiegand Door Controller
  Stefan Thesen, 2014
  Copyright: public domain -> do what you want
 
  For details visit http://blog.thesen.eu
 
  some code ideas / parts taken from Daniel Smith, www.pagemac.com
*/

#include <avr/eeprom.h>


////////////////////
// the setup routine
////////////////////
void setup()

  Serial.begin(9600);
  Serial.println(F("Wiegand Controller - S.T. 2014"));

  SetupCodeHandling();
  WiegandSetup();
  SetupUI();
 
  Serial.println(F(""));
  PrintMainMenu();
}


///////////////////////////////////////////
// main loop - handles reception & decoding
///////////////////////////////////////////
void loop()
{
  unsigned long ulFacilityCode, ulCardCode;
 
  // we have data?
  if (WiegandAvailable())
  {
    unsigned char i;
   
    Serial.print(F("Read "));
    Serial.print(WiegandBitCount());
    Serial.print(F(" bits. "));
   
    ulFacilityCode = WiegandFacilityCode();
    ulCardCode = WiegandCardCode();
    if (WiegandBitCount()!=0)
    {
      Serial.print(F("FacilityCode,CardCode = "));
      Serial.print(ulFacilityCode);
      Serial.print(F(","));
      Serial.println(ulCardCode);
      HandleCode(ulFacilityCode, ulCardCode);
    }
    else
    {
      Serial.println(F("Cannot decode. Unknown format."));
    }
   
    // clean up and get ready for the next card
    WiegandReset();
  }
}
UI.ino
/*
  User Interface Routines for Wiegand controller
  Stefan Thesen, 2014
  Copyright: public domain -> do what you want
*/

#include <avr/wdt.h>

//////////
// Globals
//////////

// note: Arduino String Objects eat (lots) of RAM dynamically and are not easy to predict
// so we do standard c 'strings', so that we can control memory
#define MAXSERBUFF 40                // max size for serial line in input
char sInBuffer[MAXSERBUFF];          // buffer for serial reading
int iMenuMode;                       // Mode flag for menu


void SetupUI()
{
  // init variables
  iMenuMode = 0;
  sInBuffer[0]=0;
}


/////////////////////////////////////////////////
// read serial input data and create input buffer
/////////////////////////////////////////////////
void serialEvent()
{
  char cc=0;
  if(Serial.available())
  {
    cc = Serial.read();
    if(cc==10||cc==13)
    {
       Serial.println(F(""));
       ProcessBuffer();
    }
    else
    {
      Serial.print(cc);
      int ipos = strlen(sInBuffer);
      if (ipos<MAXSERBUFF-1)
      {
        sInBuffer[ipos]=cc;
        sInBuffer[ipos+1]=0;
      }
    }
  }
}


//////////////////////////////////
// trigger actions by serial input
//////////////////////////////////
void ProcessBuffer()
{
  if (iMenuMode==0)
  {
    if (strcmp(sInBuffer,"1") == 0)
    {
      Serial.println(F("To add code/card enter: <Name,FacilityCode,CardCode,Action> as list or just <enter> to cancel"));
      Serial.print(F(">"));
      iMenuMode=1;
    }
    else if (strcmp(sInBuffer,"2") == 0)
    {
      Serial.println(F("To delete a code/card enter: Name"));
      Serial.print(F(">"));
      iMenuMode=2;
    }
    else if (strcmp(sInBuffer,"3") == 0)
    {
      // display all codes
      int ii;
      Serial.println(F("Codelist - Format: Name,FacilityCode,CardCode,Action"));
      for (ii=0;ii<iCodeListSize;ii++)
      {
        Serial.print(pCodeList[ii].sName);
        Serial.print(F(","));
        Serial.print(pCodeList[ii].ulFacilityCode);
        Serial.print(F(","));
        Serial.print(pCodeList[ii].ulCardCode);
        Serial.print(F(","));
        Serial.print(pCodeList[ii].bAction);
        Serial.println(F(""));
      }
      Serial.println(F("Codelist End."));
     
      iMenuMode=0;
    }
    else if (strcmp(sInBuffer,"7") == 0)
    {
      // reboot
      SetTamperFlag(false);
      asm volatile ("  jmp 0");
    }
    else if (strcmp(sInBuffer,"8") == 0)
    {
      // save to eeprom
      Serial.println(F("Saving to EEprom..."));
      SaveToEEProm();
      iMenuMode=0;
    }
    else if (strcmp(sInBuffer,"999") == 0)
    {
      // delete all codes
      iCodeListSize=0;
      Serial.println(F("Erasing EEprom..."));
      SaveToEEProm();
      iMenuMode=0;
    }
  }
  // ADD CODES AS CSV LIST
  else if (iMenuMode==1)
  {
    if (strlen(sInBuffer)==0)
    {
      iMenuMode=0;
    }
    else if (iCodeListSize<iMaxCodeList)
    {
      // find comma delimiters
      char *cFirstComma=NULL,*cSecondComma=NULL,*cThirdComma=NULL;  // set all to return code fail
      cFirstComma=strchr(sInBuffer,',');
      if (cFirstComma) cSecondComma=strchr(cFirstComma+1,',');
      if (cSecondComma) cThirdComma=strchr(cSecondComma+1,',');
      if (cFirstComma!=NULL && cSecondComma!=NULL && cThirdComma!=NULL)
      {
        pCodeList[iCodeListSize].ulFacilityCode = atol(cFirstComma+1);
        pCodeList[iCodeListSize].ulCardCode     = atol(cSecondComma+1);
        pCodeList[iCodeListSize].bAction        = atoi(cThirdComma+1);
       
        // name is max MAXNAMESIZE bytes incl termination char
        if ((cFirstComma-sInBuffer)>=MAXNAMESIZE) {cFirstComma=sInBuffer+MAXNAMESIZE-1;}
        memcpy((void*)pCodeList[iCodeListSize].sName,(void*)sInBuffer,cFirstComma-sInBuffer);
        pCodeList[iCodeListSize].sName[cFirstComma-sInBuffer]=0; // to be sure: term char
       
        // do not display status - otherwise arduino is too slow, when pasting a list
        //Serial.print(F("Entry added "));
        //Serial.print(pCodeList[iCodeListSize].sName);
        //Serial.println(F(". Next entry or hit Enter to exit."));
        //Serial.print(F(">"));
        iCodeListSize++;
      }
      else
      {
        Serial.println(F("Invalid entry! - Retry or hit Enter to exit."));
        Serial.print(F(">"));
      }
    }
    else
    {
      Serial.println(F("Maximum number of code entries reached! - Exiting."));
      iMenuMode=0;
    }   
  } 
  else if (iMenuMode==2)
  {
    // delete a code
    int ii=0;
    bool bFound=false;
    while (ii<iCodeListSize && !bFound)
    {
      if (strncmp(sInBuffer,pCodeList[ii].sName,MAXNAMESIZE)==0) {bFound=true;}
      else { ii++; }
    }
    if (bFound)
    {
      int ikill=ii;
      iCodeListSize--;
      for(ii=ikill;ii<iCodeListSize;ii++)
      {
        memcpy((void*)&pCodeList[ii],(void*)&pCodeList[ii+1],sizeof(CODELIST));
      }
      Serial.println(F("Entry removed."));
    }
    else
    {
      Serial.println(F("Entry not found!"));
    }
    iMenuMode=0;
  }
 
  // prepare for next inputs
  sInBuffer[0]=0;
  if (iMenuMode==0) {PrintMainMenu();}
}


///////////////////////
// prints the main menu
///////////////////////
void PrintMainMenu()
{
  Serial.println(F("***** MENU ****"));
  Serial.println(F("<enter> -> print this menu"));
  Serial.println(F("  1     -> learn a code / paste csv-list of codes"));
  Serial.println(F("  2     -> delete a code"));
  Serial.println(F("  3     -> display all codes"));
  Serial.println(F("  7     -> reset tamper flag & reboot"));
  Serial.println(F("  8     -> save all codes to eeprom"));
  Serial.println(F("  999   -> delete ALL codes in eeprom"));
  Serial.print  (F("Notes: Name entries max "));
  Serial.print  (MAXNAMESIZE-1);
  Serial.println(F(" characters."));
  Serial.println(F("       Action entries 1 for open, 0 for close."));
  Serial.println(F(""));
  Serial.print  (F(">"));
}
Wiegand_Controller.ino
/*
  Wiegand Door Controller
  Stefan Thesen, 2014
  Copyright: public domain -> do what you want
 
  For details visit http://blog.thesen.eu
 
  some code ideas / parts taken from Daniel Smith, www.pagemac.com
*/

#include <avr/eeprom.h>


////////////////////
// the setup routine
////////////////////
void setup()

  Serial.begin(9600);
  Serial.println(F("Wiegand Controller - S.T. 2014"));

  SetupCodeHandling();
  WiegandSetup();
  SetupUI();
 
  Serial.println(F(""));
  PrintMainMenu();
}


///////////////////////////////////////////
// main loop - handles reception & decoding
///////////////////////////////////////////
void loop()
{
  unsigned long ulFacilityCode, ulCardCode;
 
  // we have data?
  if (WiegandAvailable())
  {
    unsigned char i;
   
    Serial.print(F("Read "));
    Serial.print(WiegandBitCount());
    Serial.print(F(" bits. "));
   
    ulFacilityCode = WiegandFacilityCode();
    ulCardCode = WiegandCardCode();
    if (WiegandBitCount()!=0)
    {
      Serial.print(F("FacilityCode,CardCode = "));
      Serial.print(ulFacilityCode);
      Serial.print(F(","));
      Serial.println(ulCardCode);
      HandleCode(ulFacilityCode, ulCardCode);
    }
    else
    {
      Serial.println(F("Cannot decode. Unknown format."));
    }
   
    // clean up and get ready for the next card
    WiegandReset();
  }
}

3.2.17

Makibes 10.1 Zoll Display am Raspberry

Nachdem ich mir das Makibes Display bei Amazon gekauft hatte, habe ich versucht ihn an dem Raspberry zu betreiben.
Zu meiner Schande muss ich gestehen, dass ich 3/4 der Zeit damit verbracht hatte, das Flachbandkabel, was von der Schaltplatine kommt, mit dem LCD-Schirm zu verbinden.
Das Problem lag daran, dass ich diese schwarzen "Nupsis", die das Flachbandkabel halten sollen, ganz herausgezogen hatte.
Stattdessen muss man die mit leichtem Druck nach oben biegen, das Kabel einlegen und wieder zurück in die Ausgangsposition bringen.

Wenn das geschafft ist, kann man das Display über HDMI mit dem RPI verbinden.
Dann noch eine USB-Verbindung vom RPI zum Display und die config.txt anpassen.

Unter /boot/config.txt eintragen:

max_usb_current=1
hdmi_group=2
hdmi_mode=87
hdmi_cvt 1024 600 60 6 0 0 0

Und darauf achten, dass als "Source" HDMI gewählt ist!! (auch damit hatte ich 30 Minuten verschwendet)

Hier die Herstellerseite, die aber nicht sehr viel hergibt.

Openhab und Ecoflow Max - API Anbindung

 Ich wollte die neu erworbene Powerstation in Openhab einbinden, um den aktuellen Status (Ladestand etc.) über Openhab auswerten zu können. ...