× Benvenuti sul nostro forum su Sint Wind PI!

Postate qui domande o segnalate problemi / bug che riscontrate,

map-pin SWPI Plugins

More
10 years 11 months ago - 10 years 11 months ago #411 by tony
SWPI Plugins was created by tony
Seguendo l'idea di Sandro ( anche di altri che mi hanno contattato per applicazioni particolari ) ho implementato a partire dalla versione 01.18.31 un semplice plugin manager per SWPI.

Praticamente troverete una sottocartella in più ("plugins") nella quale potere mettere i vostri moduli personalizzati che verranno caricati da SWPI.

Nella sotto-cartella troverete anche un esempio ( che non viene caricato ) . L'uso è molto banale :

Seguendo l'esigenza di Sandro con le tende da sole supponiamo di averle collegate al pin GPIO 4. Ogni 5 minuti il pluging controllerà l'intensità del vento e alzerà o abbasserà le tende di conseguenza.

E' solo un esempio e ovviamente và ottimizzato ma spero dia una idea dell'uso dei plugin:

class swpi_plugin(threading.Thread):  #  do not change the name of the class
    
    def __init__(self,cfg):
        self.cfg = cfg
        threading.Thread.__init__(self)
        

        ###################### Plugin Initialization ################
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(4, GPIO.OUT)   
        GPIO.output(4, 0)
        ###################### End Initialization ##################
        
        
    def run(self):
        log("Starting plugin : %s" % sys.modules[__name__])
   
        while 1:
            ###################### Plugin run
            if globalvars.meteo_data.wind_ave > 15: 
                GPIO.output(4, 1)
            else:
                GPIO.output(4, 0)
            ###################### end of Plugin run
            
            time.sleep(300)


Python è un linguaggio molto semplice da imparare ( non lo conoscevo prima di iniziare a lavorare su SWPI ) .
Per iniziare fatevi una copia del file di esempio chiamandolo per esempio tende.py e a quel punto verrà caricato
Modificate il codice tra le righe con i cancelletti per inizializzare e per gestire il loop principale
Last edit: 10 years 11 months ago by tony.
The following user(s) said Thank You: alegrechi

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago #418 by tetox
Replied by tetox on topic SWPI Plugins
Ciao Tony ...buona sera ...
Utilizzando il plugin spiegato sopra ...invece di controllare il vento , o altro evento ...non si pottrebbe controllare "l'avvenuto scatto della Cam" , e far scattare un qualsiasi gpio?? .
Che interrogazione dovrei fare per sapere che lo "scatto " e' appena avvenuto ??.(mi riallaccio alla mia richiesta fatta qualche tempo fa' )
Grazie Tony ...
Stefano

Please Log in to join the conversation.

More
10 years 11 months ago #419 by tony
Replied by tony on topic SWPI Plugins
Stefano,

Non con questa versione che è asincrona rispetto al ciclo di scatto. Dovresti implementare un pooling.
Vedo magari di aggiungerne uno fisso ma di tipo sincrono.

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago #423 by tetox
Replied by tetox on topic SWPI Plugins
Grazie Tony...
aspettero' fiducioso il tuo intervento...
Ciao ciao
Stefano

ps:quando hai 5 minuti di relax pensa anche a come implementare la possibilita' di mandare i dati al CWOP
byeeee

Please Log in to join the conversation.

More
10 years 11 months ago - 10 years 11 months ago #424 by tony
Replied by tony on topic SWPI Plugins
ora nella 01.18.48 c'è anche il plugin sincrono.

Nella cartella pugins c'è il file di esempio :

sync_plugin.py.example

per attivarlo basta rinomnarlo in sync_plugin.py eliminando example :
mv sync_plugin.py.example sync_plugin.py


A quel punto verrà caricato. Per personalizzarlo al solito và modificato il codice tra i cancelletti in tre punti:

Il primo per inizializzare eventuali variabili
il secondo è il codice che viene eseguito prima dell'inizio de ciclo principale
Il terzo viene eseguito dopo il ciclo principale
        
        ###################### Plugin Initialization ################
        log("Intitializing sync_plug-in " )
 #       GPIO.setmode(GPIO.BCM)
 #       GPIO.setwarnings(False)
 #       GPIO.setup(4, GPIO.OUT)   
 #       GPIO.output(4, 0)
        ###################### End Initialization ##################
        
        
    def run_before(self):
        log("Running sync plugin [run_before]..")
        ###################### Plugin run
        
#        if globalvars.meteo_data.wind_ave > 15: 
#            GPIO.output(4, 1)
#        else:
#            GPIO.output(4, 0)
        ###################### end of Plugin run


    def run_after(self):
        log("Running sync plugin [run_after]..")

        ###################### Plugin run
  #      if globalvars.meteo_data.wind_ave > 15: 
  #          GPIO.output(4, 0)
  #      else:
  #          GPIO.output(4, 1)
        ###################### end of Plugin run
Last edit: 10 years 11 months ago by tony.
The following user(s) said Thank You: alegrechi

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago #425 by tetox
Replied by tetox on topic SWPI Plugins
Grazie tony...
appena rientro in italia (sabato/domenica)provero' immediatamente
il plugin ...entro la prossima settimana riferiro' .
grazie ancora
stefano

Please Log in to join the conversation.

More
10 years 11 months ago #427 by pfeifer
Replied by pfeifer on topic SWPI Plugins
Che dire Tony,
sei stato velocissimo.
Non resta che provare :-)
Grazie mille
Sandro

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago - 10 years 11 months ago #433 by tetox
Replied by tetox on topic SWPI Plugins
Sera a tutti..
Non ho resistito e ho provato subito il plugin ..
purtroppo a me' blocca l'esecuzione sia dell'invio dati , sia lo scatto cam.
Disattivato il plugin tutto e' ritornato ok , ho notato che nella cartella Plugin c'e' il file __init__.py che e' vuoto , valore 0 (zero) e' giusto cosi' ???
Dai Tony ..che se funzionera' questa cosa ...aprira' un mondo di giochi !!
Ciao Stefano
Last edit: 10 years 11 months ago by tetox.

Please Log in to join the conversation.

More
10 years 11 months ago - 10 years 11 months ago #434 by tony
Replied by tony on topic SWPI Plugins
ok. do una occhiata quanto prima

__init__.py deve essere vuoto e non lo rimuovere.
Posta il codice del tuo plugin
Last edit: 10 years 11 months ago by tony.

Please Log in to join the conversation.

More
10 years 11 months ago - 10 years 11 months ago #436 by tony
Replied by tony on topic SWPI Plugins
Giusto un esempio di plugin asincrono:

Per la stazione in montagna avevo la necessità di svincolare l'invio dei dati a WeatherUndergraund dagli scatti della camera. Volevo l'aggiornamento dei dati a 1 minuto ma non volevo scattare foto ogni minuto per non bruciare prematuramente il CCD. Ecco il plugin. Sono solo 2 righe di codice da inserire tra i cancelletti dell'esempio fornito.
time.sleep(60-datetime.datetime.now().second) 
logDataToWunderground(self.cfg.WeatherUnderground_ID,self.cfg.WeatherUnderground_password)
La prima riga attende lo scoccare del minuto mentre la seconda invia i dati. A questo punto ho disattivato l'invio tramite ciclo principale.
Sotto il file completo


Attachment wunderground.rar not found

Attachments:
Last edit: 10 years 11 months ago by tony.

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago #438 by tetox
Replied by tetox on topic SWPI Plugins
Buon giorno Tony..
Io ho attivato il plugin modificando solamente questo :
###########################################################################
#     Sint Wind PI
#     Copyright 2012 by Tonino Tarsi <tony.tarsi@gmail.com>
#   
#     USB comunication based pywws by 'Jim Easterbrook' <jim@jim-easterbrook.me.uk>
#     Please refer to the LICENSE file for conditions 
#     Visit http://www.vololiberomontecucco.it
# 
##########################################################################

"""example plugin."""

import threading
import random
import datetime
import sqlite3
import sys
import subprocess
import sys 
import os
import thread
import time

import globalvars
import meteodata
from TTLib import  *
import RPi.GPIO as GPIO



class swpi_sync_plugin(object):  #  do not change the name of the class
    
    def __init__(self,cfg):
        self.cfg = cfg

        
        ###################### Plugin Initialization ################
        log("Intitializing sync_plug-in " )
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(4, GPIO.OUT)   
        GPIO.output(4, 0)
T =0.5

        ###################### End Initialization ##################
        
        
    def run_before(self):
        log("Running sync plugin [run_before]..")
        ###################### Plugin run
        
#        if globalvars.meteo_data.wind_ave > 15: 
#            GPIO.output(4, 1)
#        else:
#            GPIO.output(4, 0)
        ###################### end of Plugin run


    def run_after(self):
        log("Running sync plugin [run_after]..")

        ###################### Plugin run
  #      if globalvars.meteo_data.wind_ave > 15: 
  #          GPIO.output(4, 0)
  #      else:
  #          GPIO.output(4, 1)

 GPIO.output(4, 1)
  time.sleep(T)
   GPIO.output(4, 0)

        ###################### end of Plugin run

in pratica dopo il def run_after(self):
mi dovrebbe attivare il gpio 4 per mezzo secondo .
Comunque nel pomeriggio lo riprovo di nuovo , perche' mi sembra di non aver fatto nulla di strano.
Buon pranzo Tony ..alla prossima
Stefano

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago #439 by tetox
Replied by tetox on topic SWPI Plugins
Arieccomi !!
Riprovando il plugin e controllando da terminale esce questo errore :
10.....9.....8.....7.....6.....5.....4.....3.....2.....1.....
[28/04/2013-15:36:42] Checking internet connetion ...
[28/04/2013-15:36:42] Starting sensor reading - Sensor type is : WM918
[28/04/2013-15:36:42] Thread started
[28/04/2013-15:36:42] Opening serial port
[28/04/2013-15:36:42] Serial port open
[28/04/2013-15:36:42] Internet ok
[28/04/2013-15:36:42] Checking internet connetion ...
[28/04/2013-15:36:42] Internet ok
[28/04/2013-15:36:43] Connected with IP : 2.32.18.128
[28/04/2013-15:36:43] Local IP :192.168.1.99 Public IP :  2.32.18.128
[28/04/2013-15:36:43] Config Server running on port 80
[28/04/2013-15:36:43] Starting General WatchDog
dom 28 apr 2013, 15.36.43, CEST
[28/04/2013-15:36:43] System time adjusted from NPT server : europe.pool.ntp.org
[28/04/2013-15:36:46] Mail sent to :tetotex@gmail.com
[28/04/2013-15:36:46] Calculating Meteo data and statistics
[28/04/2013-15:36:48] Deleting file from Canon PowerShot S45 (normal mode)
[28/04/2013-15:36:49] loading plugins
[28/04/2013-15:36:49] Loading sync plugin
Traceback (most recent call last):
  File "swpi.py", line 662, in <module>
    import plugins.sync_plugin as pls
  File "/home/pi/swpi/plugins/sync_plugin.py", line 48
    def run_before(self):
    ^
IndentationError: unexpected indent

alla linea 48 c'e' questo:
def run_before(self):
        log("Running sync plugin [run_before]..")

Per ora e' tutto..
Stefano

Please Log in to join the conversation.

More
10 years 11 months ago - 10 years 11 months ago #440 by tony
Replied by tony on topic SWPI Plugins
Solito problema con gli indent di python.
Python non ha parentesi o altro per delimitare i blocchi di codice ma usa l'indentazione che deve sempre esser la stessa su tutto il modulo.

Il codice corretto è :
###########################################################################
#     Sint Wind PI
#     Copyright 2012 by Tonino Tarsi <tony.tarsi@gmail.com>
#   
#     USB comunication based pywws by 'Jim Easterbrook' <jim@jim-easterbrook.me.uk>
#     Please refer to the LICENSE file for conditions 
#     Visit http://www.vololiberomontecucco.it
# 
##########################################################################

"""example plugin."""

import threading
import random
import datetime
import sqlite3
import sys
import subprocess
import sys 
import os
import thread
import time

import globalvars
import meteodata
from TTLib import  *
import RPi.GPIO as GPIO



class swpi_sync_plugin(object):  #  do not change the name of the class

    def __init__(self,cfg):
        self.cfg = cfg
        ###################### Plugin Initialization ################
        log("Intitializing sync_plug-in " )
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(4, GPIO.OUT)   
        GPIO.output(4, 0)
        selt.T = 0.5

        ###################### End Initialization ##################
        
        
    def run_before(self):
        log("Running sync plugin [run_before]..")


    def run_after(self):
        log("Running sync plugin [run_after]..")
        GPIO.output(4, 1)
        time.sleep(self.T)
        GPIO.output(4, 0)

        ###################### end of Plugin run
Last edit: 10 years 11 months ago by tony.

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago #441 by tetox
Replied by tetox on topic SWPI Plugins
Tony ...
Non gli e' piaciuto neanche questa volta !!
[28/04/2013-18:42:37] Calculating Meteo data and statistics
[28/04/2013-18:42:38] Deleting file from Canon PowerShot S45 (normal mode)
[28/04/2013-18:42:39] loading plugins
[28/04/2013-18:42:39] Loading sync plugin
[28/04/2013-18:42:39] Intitializing sync_plug-in
Traceback (most recent call last):
  File "swpi.py", line 663, in <module>
    plugin_sync = pls.swpi_sync_plugin(cfg)
  File "/home/pi/swpi/plugins/sync_plugin.py", line 41, in __init__
    selt.T = 0.5
NameError: global name 'selt' is not defined
[28/04/2013-18:42:42] Logging data to Database
[28/04/2013-18:42:42] Dir: E - Spd: 7.92 - Gst: 9.36 - T: 22.6 - P: 1013.4 - U: 27 - R: 0 - CB: 2494
^C^C
Per l'indentazione errata ...mi son tirato le orecchie da solo !! :sick:
logicamente questa prova l'ho fatta con l'ultimo codice postato da te.
Bye
Stefano

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago #442 by tetox
Replied by tetox on topic SWPI Plugins
Tonyyyy..!!!
ho rimediato ....a modo mio ..sic!!!
ho tolto selt.T = 0.5
e ho messo direttamente time.sleep(0.5)
lo so' che e' poco elegante maa funzionaaa!!
Tony ..mettiti in posa ...che ti facciamo un monumento ..
grazie grazie
Stefano

Please Log in to join the conversation.

More
10 years 11 months ago - 10 years 11 months ago #443 by tony
Replied by tony on topic SWPI Plugins
si .. avevo sbagliato a scrivere "self" in "selt" ma và benissimo anche come hai fatto tu :-)
Last edit: 10 years 11 months ago by tony.

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago #479 by tetox
Replied by tetox on topic SWPI Plugins
Ciao ..
Sto' cercando di aggiungere al sync_plugin (che funziona alla perfezione !!)
questo ulteriore comando
def run(self):
        log("Starting plugin : %s" % sys.modules[__name__])
   
        while 1:
            ###################### Plugin run
            if globalvars.meteo_data.temp_in > 20: 
                SendMail(self.cfg, "Temperatura", "La temperatura ha superato i 20 gradi", None):
            ###################### end of Plugin run
Purtroppo mi restituisce un "errore di sintassi "
..ma dove sara' questo errore ??
Grazie Tony ..
Stefano

Please Log in to join the conversation.

More
10 years 11 months ago #480 by tony
Replied by tony on topic SWPI Plugins
Stefano,
C'è un ":" di troppo alla fine dell'istruzione SendMail.
I ":" vanno solo messi alla fine delle istruzioni di controllo (if,else,while,for....)

Please Log in to join the conversation.

  • tetox
  • tetox's Avatar
  • Visitor
  • Visitor
10 years 11 months ago #490 by tetox
Replied by tetox on topic SWPI Plugins
Grazie Tony ...come sempre gentile e paziente ..
Solo che' tolti i ":" l'errore e' sparito , pero' lo script sembra non funzionare .io ho provato a fare cosi' :
cut....
cut...
def run_after(self):
        log("Running sync plugin [run_after]..")

        ###################### Plugin run
  
        GPIO.output(4, 1)
        time.sleep(0.5)
        GPIO.output(4, 0)
        
        time.sleep(10)

    def run(self):
        log("Starting plugin : %s" % sys.modules[__name__])
        while 1:        
            if globalvars.meteo_data.temp_in > 18: 
                SendMail(self.cfg, "Temperatura", "La temperatura ha superato i 18 gradi", None)

        ###################### end of Plugin run
Non parte nessuna email , (logicamente la temperatura e' superiore ai 18 gradi) , poi ho provato cosi:
def run_after(self):
        log("Running sync plugin [run_after]..")

        ###################### Plugin run
  
        GPIO.output(4, 1)
        time.sleep(0.5)
        GPIO.output(4, 0)
        time.sleep(10)
        
        if globalvars.meteo_data.temp_in > 18: 
             SendMail(self.cfg, "Temperatura", "La temperatura ha superato i 18 gradi", None)

        ###################### end of Plugin run
In questa maniera mi da questo errore :
[04/05/2013-16:40:59] ERROR sending mail
Exeption coercing to Unicode: need string or buffer, NoneType found

Quale e' la giusta sequenza??
Stefano

Please Log in to join the conversation.

More
10 years 11 months ago #493 by tony
Replied by tony on topic SWPI Plugins
Ha sempre ragione lui :-)

il comando corretto è :

SendMail(self.cfg, "Temperatura", "La temperatura ha superato i 18 gradi", "")

Togli io None metti una stringa vuota come attachment ""

Please Log in to join the conversation.

  • Mario201303
  • Mario201303's Avatar
  • Visitor
  • Visitor
10 years 10 months ago #901 by Mario201303
Replied by Mario201303 on topic SWPI Plugins
Salve, prima di tutto vi ringrazio per le risposte date.
Volevo sapere se si può fare un plugins che ad una certa velocità del vento e direzione chiama un numero di cellulare, grazie

Please Log in to join the conversation.

More
10 years 10 months ago #1160 by Roberto Vaccaro
Replied by Roberto Vaccaro on topic SWPI Plugins
Ciao Tony
sto provando questo plugin:
###########################################################################
#     Sint Wind PI
#     Copyright 2012 by Tonino Tarsi <tony.tarsi@gmail.com>
#   
#     USB comunication based pywws by 'Jim Easterbrook' <jim@jim-easterbrook.me.uk>
#     Please refer to the LICENSE file for conditions 
#     Visit http://www.vololiberomontecucco.it
# 
##########################################################################

"""example plugin."""

import threading
import random
import datetime
import sqlite3
import sys
import subprocess
import sys 
import os
import thread
import time

import globalvars
import meteodata
from TTLib import  *
import RPi.GPIO as GPIO



class swpi_sync_plugin(object):  #  do not change the name of the class
    
    def __init__(self,cfg):
        self.cfg = cfg

        
        ###################### Plugin Initialization ################
        log("Intitializing sync_plug-in " )
 #       GPIO.setmode(GPIO.BCM)
 #       GPIO.setwarnings(False)
 #       GPIO.setup(4, GPIO.OUT)   
 #       GPIO.output(4, 0)
        ###################### End Initialization ##################
        
        
    def run_before(self):
        log("Running sync plugin [run_before]..")
        ###################### Plugin run
        
#        if globalvars.meteo_data.wind_ave > 15: 
#            GPIO.output(4, 1)
#        else:
#            GPIO.output(4, 0)
        ###################### end of Plugin run


    def run_after(self):
        log("Running sync plugin [run_after]..")

        ###################### Plugin run
  #      if globalvars.meteo_data.wind_ave > 15: 
  #          GPIO.output(4, 0)
  #      else:
  #          GPIO.output(4, 1)

	 
        
        if globalvars.meteo_data.temp_in > 18: 
             SendMail(self.cfg, "Temperatura", "La temperatura ha superato i 18 gradi","")

        ###################### end of Plugin run
vedo da log che viene caricato senza errori ma non ricevo nessuna e-mail, ovviamente la temperatura interna è superiore ai 18°.

Un'altra domanda il tuo plugin "AllLogger" funziona solo su wunderground o anche sull'invio del file meteo.txt ?

Please Log in to join the conversation.

More
10 years 10 months ago #1161 by Roberto Vaccaro
Replied by Roberto Vaccaro on topic SWPI Plugins
:) Tutto risolto!

Please Log in to join the conversation.

More
10 years 10 months ago #1162 by tony
Replied by tony on topic SWPI Plugins
Bene :-)

Postalo come allegato ( ho abilitato l'upload dei .py ) . Un pluging che invia mail al superamento di una certa temperatura può essere utile ad altri.

Please Log in to join the conversation.

More
10 years 10 months ago #1163 by Roberto Vaccaro
Replied by Roberto Vaccaro on topic SWPI Plugins
Volentieri, ma è quello che aveva fatto tetox

Please Log in to join the conversation.

More
10 years 10 months ago #1165 by tony
Replied by tony on topic SWPI Plugins
ok :-)

Please Log in to join the conversation.

More
10 years 9 months ago #1366 by Elia
Replied by Elia on topic SWPI Plugins
Salve ho configurato la mia centralina Come da guida e volevo sapere se per far si che venga eseguito un plugin basta solo posizionare uno script dentro la cartella plugin grazie

Please Log in to join the conversation.

More
10 years 9 months ago #1369 by Roberto Vaccaro
Replied by Roberto Vaccaro on topic SWPI Plugins
Si certamente
Ovviamente il plugin deve essere scritto correttamente.
The following user(s) said Thank You: Mario201303

Please Log in to join the conversation.

More
10 years 9 months ago #1374 by Elia
Replied by Elia on topic SWPI Plugins
Salve, volevo sapere come mai mi da questo errore se uso un plugins grazie:
[10/07/2013-22:22:31] Trying to get time from WH1080. Please wait ...
Exception happened during processing of request from ('78.13.144.194', 50045)
mer 10 lug 2013, 22.23.00, CEST

Please Log in to join the conversation.

More
10 years 9 months ago #1375 by Elia
Replied by Elia on topic SWPI Plugins
Salve, forse ho trovato l'errore, volevo chiedervi se sono presenti le librerie urlib2, httplib e urlib grazie

Please Log in to join the conversation.

Time to create page: 1.054 seconds