Ich wäre erstmal an einer Softwarelösung interessiert.
Funksteckdosen,... mit iOS & Android (Version 2)
-
-
Funksteckdosen,... mit iOS & Android (Version 2)? Schau mal ob du hier fündig wirst!
-
Da ist nix mit Software zu machen.
-
Da ist nix mit Software zu machen.sicher ? auch nicht mit runtertakten und Task killen oder stoppen, Hintergrunddienste stoppen? sollte den Strombedarf doch verringern
hier war doch schon mal ein Beispiel ohne Hardwareumbau....wenn ich nur wüsste wo....
auch im minimal raspbian sollten sich Hinweise finden lassen.....
-
Hey,
Ich hätte noch eine neue Frage.Ich habe jetzt die App,den RPi und so weiter alles (denke ich) passend eingestellt.Beim Ausführen des Skripts kommt allerdings immer der Fehler
Was kann ich machen um diesen Error zu beseitigen ?MfG
HuntX76 -
- Offizieller Beitrag
-
Das andere wäre mir lieber,denn so kommt das hier :
Code
Alles anzeigenpi@raspberrypi ~/netio_server $ sudo python netio_server.py init light status read state from file Traceback (most recent call last): File "netio_server.py", line 1105, in <module> server_init(server_init_mode) #reset used to switch off all lights File "netio_server.py", line 1046, in server_init light_state = pickle.load( open( pickle_file, "rb" ) ) File "/usr/lib/python2.7/pickle.py", line 1378, in load return Unpickler(file).load() File "/usr/lib/python2.7/pickle.py", line 858, in load dispatch[key](self) File "/usr/lib/python2.7/pickle.py", line 880, in load_eof raise EOFError EOFError
Tja,was nun ?
-
Hallo
Hab ein Problemchen.....
GPIO mit 0 und 1 über NETIO kann ich ansteuern.
Aber wie kann ich den aktuellen Status der LED abfragen?Folgende Einstellungen funktioniert nicht
gpio status gpio2
oder
gpio check gpio2siehe Bild
Vielen Dank im Voraus
Grüße
Mal endlich wieder ein update ....Ich habe heute erst gesehen, das Bart/Tobi eine Funktion für die Ansteuerung von GPIO Ports implementiert hat.
NetIO App Spielereien [Gemeinschaftsprojekt]Diese habe ich jetzt in das Script für alle eingebaut.
Die "Funktion" habe ich allerdings nicht led sondern gpio benannt, da dies allgemeiner ist.Aufruf über Netio mittels:
gpio set gpio7 1Wie von Tobi beschrieben, muss der Port entsprechend vorbereitet sein:
Bash
Alles anzeigen#!/bin/sh echo "7" > /sys/class/gpio/export echo "8" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio7/direction echo "out" > /sys/class/gpio/gpio8/direction chmod 666 /sys/class/gpio/gpio7/value chmod 666 /sys/class/gpio/gpio8/value
Bitte probiert dies aus und gebt mir Rückmeldung, falls es nicht funktioniert.
Python
Alles anzeigen#!/usr/bin/python # -*- coding: utf-8 -*- # server for netio server # 2013-12-03 V1.8 by Thomas Hoeser # ChangeLog V1.8 # gpio added - provided by Bart / Tobi # https://forum-raspberrypi.de/forum/thread/4179-netio-app-spielereien-gemeinschaftsprojekt/ from netio_config import HOST, PORT, light_dict,sensor_dict, time_multi,debug_level,verbose_level,oscmd_Light, pickle_file,server_init_mode,oscmd_Light2,timer_mode,t,lan_dict,log_level,log_file, openweather_path # ----------------------------------------------------------------------------------------------- # usually you do not need change the code below # To do: # read from remote database avrio import locale # locale.setlocale(locale.LC_ALL, 'de_DE') import SocketServer, socket SocketServer.TCPServer.allow_reuse_address = True # if the server is getting terminated with Ctrl-C the socket is not closed and you need to wait sometime # allow_reuse_address will overcome this import sys import os import subprocess import random import pickle import time import threading import argparse # analyze command line arguments import urllib2, json, pprint from datetime import datetime, timedelta # Name to be used in NetIO for on and off LightCmdOn = "an" LightCmdOff = "aus" LightCmdStatus = "status" LightCmdStop = "stop" LanCmdOn = "an" LanCmdOff = "aus" LanCmdStatus = "status" # The following dict looks odd - but I started wiht a different concept. server_dict = { "read" : "read", "licht" : oscmd_Light, "licht2" : oscmd_Light2, "wetter" : "wetter", "temp" : "Temp", "system" : "system", "timer" : "Timer", "linux" : "Linux", "lan" : "Lan", "log" : "Log", "gpio" : "gpio", "dict" : "dict" } # dictionary with will be create during init phase of server light_state = {} timer_state = {} # multiple timers - not yet implemented timer = [0,0,0,0,0] LightMode = 0 server_cmd = "" server_reply= "" client_cmd = "" os_cmd = "" send433 = 0 # ring buffer for log entries class RingBuffer: def __init__(self, size): self.data = [None for i in xrange(size)] def append(self, x): self.data.pop(0) self.data.append(x) def get(self): return self.data max_log_entries = 100 log_buffer = RingBuffer(max_log_entries) log_buffer.append("server definitions loaded") id_dict_name = { '01d' : ['d_0_M','wolkenlos'], # 'sky is clear' '01n' : ['n_0_M','wolkenlos'], # 'sky is clear' '02d' : ['d_1_M','leicht_bewoelkt'], # 'few clouds' '02n' : ['n_1_M','leicht_bewoelkt'], # 'few clouds' '03d' : ['d_2_M','bewoelkt'], # 'scattered clouds' '03n' : ['n_2_M','bewoelkt'], # 'scattered clouds' '04d' : ['d_3_M','bedeckt'], # 'broken clouds' '04n' : ['n_3_M','bedeckt'], # 'broken clouds' '09d' : ['d_5_M','Schauer'], # 'shower rain' '09n' : ['n_5_M','Schauer'], # 'shower rain' '10d' : ['d_55_M','Regen'], # 'Rain' '10n' : ['n_55_M','Regen'], # 'Rain' '11d' : ['d_9_M','Gewitter'], # 'Thunderstorm' '11n' : ['n_9_M','Gewitter'], # 'Thunderstorm' '13d' : ['d_61_M','Schnee'], # 'snow' '13n' : ['n_61_M','Schnee'], # 'snow' '50d' : ['d_4_M','Nebel'], # 'mist' '50n' : ['n_4_M','Nebel'] # 'mist' } #--------------------------------------------------------------------------------------------- def srvcmd_gpio(server_cmd,client_words,client_args): # examples # "gpio", "set", "gpio7", "1" # "gpio", "set", "gpio7", "0" # "gpio", "check", "gpio7" if verbose_level > 2: print "++++ srvcmd_gpio()" server_reply = "unf: srvcmd_gpio" if client_words[1] == "set": GPIO = client_words[2] LEDValue = client_words[3] file = "/sys/class/gpio/"+GPIO+"/value" f = open(file, 'w') f.write(LEDValue) f.close server_reply = "Written " + LEDValue + " to " + GPIO elif client_words[1] == "check": GPIO = client_words[2] file = "/sys/class/gpio/"+GPIO+"/value" f = open(file, 'r') server_reply = f.read() else: server_reply = "wrong command" return(server_reply) #--------------------------------------------------------------------------------------------- def systemInfo(server_cmd,client_words,client_args): # von Mario if verbose_level > 2: print "++++ systemInfo()" server_reply = "unf: systemInfo" # vcgencmd measure_clock arm Taktfrequenz abfragen # clock: arm, core, h264, isp, v3d, uart, pwm, emmc, pixel, vec, hdmi, dpi. # vcgencmd measure_temp Temperatur auslesen # vcgencmd get_mem arm/gpu # vcgencmd measure_volts core Spannung abfragen # volts: core, sdram_c, sdram_i, sdram_p hardware = client_words[1] hardware = hardware.lower() info = client_words[2] info = info.lower() if hardware == "cpu": if info == "temp": res = os.popen('vcgencmd measure_temp').readline() server_reply = (res.replace("temp="," ").replace("'C\n","")) elif info == "use": server_reply = "bald" return(server_reply) #--------------------------------------------------------------------------------------------- def ow_id2icon(id): if verbose_level > 2: print "++++ ow_id2icon()" print "id = ", id id_entry = id_dict_name.get(id) icon_name = id_entry[0] icon_text = id_entry[1] if verbose_level > 2: print icon_name print icon_text return(icon_name,icon_text) #--------------------------------------------------------------------------------------------- def temp_k2c(temp_k): temp_c = round(temp_k - 273.15,1) return(temp_c) #--------------------------------------------------------------------------------------------- def speed_mps2ms(speed_mps): speed_ms = round(speed_mps * 0.44704,1) return(speed_ms) #--------------------------------------------------------------------------------------------- def wind_deg2txt(deg): # 0 1 2 3 4 5 6 7 8 wind_dir_name = ['N','NO','O','SO','S','SW','W','NW','N'] wind_sections = 360 / 8 offset = wind_sections / 2 # range(start, stop[, step]) y = int( (deg + offset) / wind_sections ) if verbose_level > 3 :print deg, y, offset, wind_sections, wind_dir_txt = wind_dir_name[y] if verbose_level > 3 :print " -> " + wind_dir_txt return(wind_dir_txt) #--------------------------------------------------------------------------------------------- def ow_read_field(ow_city,owField): # # NetIO: Wetter {city} {field} # fields provided using field help - see below if verbose_level > 2: print "++++ ow_read_field()" server_reply = "unf: ow_read_field" ow_file_cur = openweather_path + "/ow_" + ow_city + "_cur.json" try: with open(ow_file_cur, 'r') as json_file: json_out_cur = json.load(json_file) except: server_reply = "PANIC: cannot open file: " + ow_file_cur sys.stderr.write(server_reply) return(server_reply) ow_file_for = openweather_path + "/ow_" + ow_city + "_for7.json" try: with open(ow_file_for, 'r') as json_file: json_out_for = json.load(json_file) except: server_reply = "PANIC: cannot open file: " + ow_file_for return(server_reply) for_count = 7 UX_Fcst = json_out_cur['dt'] # read UNIX Timestamp from JSON file DT_Fcst = datetime.fromtimestamp(UX_Fcst) # create datetime object using UNIX timestamp DayDelta = timedelta(days=1) # define delta to add if owField == "help": server_reply = "stand, temp, tempmax, tempmin, wind, windg, windr, aufgang, untergang, feuchte, druck, wolken, himmel, icon, owid, tag" elif owField == "tag": server_reply = DT_Fcst.strftime("%a") # get weekday from datetime object print server_reply for x in range(0,for_count): DayX = DT_Fcst + timedelta(days=x+1) # calculate foredcast date server_reply += " " + DayX.strftime("%a")# get weekday from datetime object elif owField == "stand": status = datetime.fromtimestamp(json_out_cur['dt']).strftime('%Y-%m-%d %H:%M') server_reply = "Stand: " + status elif owField == "aufgang": aufgang = datetime.fromtimestamp(json_out_cur['sys']['sunrise']).strftime('%H:%M') server_reply = "SonnenAufgang: " + aufgang elif owField == "untergang": untergang = datetime.fromtimestamp(json_out_cur['sys']['sunset']).strftime('%H:%M') server_reply = "SonnenUntergang: " + untergang elif owField == "temp": server_reply = "Temp: " + str(temp_k2c ( json_out_cur['main']['temp'] )) + " Grad" for x in range(0,for_count): server_reply += " | " + str(temp_k2c ( json_out_for['list'][x]['temp']['day'] )) elif owField == "tempmax": server_reply = "Temp Max: " + str(int(temp_k2c ( json_out_cur['main']['temp_max'] ))) + " Grad" for x in range(0,for_count): server_reply += " | " + str(int(temp_k2c ( json_out_for['list'][x]['temp']['max'] ))) elif owField == "tempmin": server_reply = "Temp Min: " + str(int(temp_k2c ( json_out_cur['main']['temp_min'] ))) + " Grad" for x in range(0,for_count): server_reply += " | " + str(int(temp_k2c ( json_out_for['list'][x]['temp']['min'] ))) elif owField == "windg": wind_speed = json_out_cur['wind']['speed'] wind_speed = speed_mps2ms(wind_speed) server_reply = "Windgeschwindigkeit: " + str(wind_speed) + " m/s" for x in range(0,for_count): server_reply += " | " + str(speed_mps2ms( json_out_for['list'][x]['speed'])) elif owField == "windr": server_reply = "Windrichtung: " + str(json_out_cur['wind']['deg']) + " Grad" for x in range(0,for_count): server_reply += " | " + str(int( json_out_for['list'][x]['deg'])) elif owField == "wind": server_reply = wind_deg2txt(json_out_cur['wind']['deg']) for x in range(0,for_count): server_reply += " | " + wind_deg2txt(json_out_for['list'][x]['deg']) elif owField == "wolken": server_reply = "Wolken: " + str(json_out_cur['clouds']['all']) + "%" for x in range(0,for_count): server_reply += " | " + str(json_out_for['list'][x]['clouds']) elif owField == "himmel": icon = ow_id2icon(json_out_cur['weather'][0]['icon']) server_reply = icon[1] for x in range(0,for_count): icon = ow_id2icon(json_out_for['list'][x]['weather'][0]['icon']) server_reply += " " + icon[1] elif owField == "image": icon = ow_id2icon(json_out_cur['weather'][0]['icon']) server_reply = " " + icon[0] for x in range(0,for_count): icon = ow_id2icon(json_out_for['list'][x]['weather'][0]['icon']) server_reply += " " + icon[0] elif owField == "icon": server_reply = "Himmel Icon: " + str(json_out_cur['weather'][0]['icon']) + "" for x in range(0,for_count): server_reply += " | " + str(json_out_for['list'][x]['weather'][0]['icon']) elif owField == "owid": server_reply = "Himmel ID: " + str(json_out_cur['weather'][0]['id']) + "" for x in range(0,for_count): server_reply += " | " + str(json_out_for['list'][x]['weather'][0]['id']) elif owField == "feuchte": server_reply = "Feuchte: " + str(json_out_cur['main']['humidity']) + " %" for x in range(0,for_count): server_reply += " | " + str(int( json_out_for['list'][x]['humidity'] )) elif owField == "druck": DruckVortag = int(json_out_cur['main']['pressure']) server_reply = str(DruckVortag) + " h" for x in range(0,for_count): DruckAktuell = int( json_out_for['list'][x]['pressure']) server_reply += " | " + str(DruckAktuell) DruckDelta = DruckVortag - DruckAktuell DruckTendenz = 10 if (DruckDelta > 20): server_reply += " N" # fallend elif (DruckDelta > 10): server_reply += " NW" # leicht fallend elif (DruckDelta < -20): server_reply += " SW" # steigend elif (DruckDelta < -10): server_reply += " S" # leicht steigend else: server_reply += " W" # gleich DruckVortag = DruckAktuell else: server_reply = "unknown field: " + owField print server_reply return(server_reply) #--------------------------------------------------------------------------------------------- def srvcmd_weather(server_cmd,client_words,client_args): # examples # "send", "Wetter", "Wiehl", "Temp" if verbose_level > 2: print "++++ srvcmd_weather()" if verbose_level > 2: print "weather client_words : ", client_words print "weather client_args : ", client_args if (client_args < 3): server_reply = "not enougth arguments for command " + client_cmd print server_reply return (server_reply) # get name of field provided as second argument OwCity = client_words[1] # 2nd argument OwCity = OwCity.lower() OwField = client_words[2] # 3rd argument OwField = OwField.lower() if (OwField == "vor"): if (client_args < 4): server_reply = "not enougth arguments for command " + client_cmd else: OwDay = client_words[3] # 4th argument server_reply = ow_read_field_fcst(OwCity,OwDay) else: server_reply = ow_read_field(OwCity,OwField) return(server_reply) #--------------------------------------------------------------------------------------------- def unix_cmd(os_cmd): # cmd = 'echo "Hello world!"' # to be used as test for checking popen server_reply = "unix_cmd()" if debug_level == 0: # OLD - process = os.popen(os_cmd) if verbose_level > 0: print "subprocess.Popen:", os_cmd process = subprocess.Popen(os_cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) system_reply = process.communicate() # process.poll() poll response - but doe not wait for process to be finished process.wait() system_retcode = process.returncode if system_retcode: server_reply= "ERROR: " + str( system_retcode) + ": " + str(system_reply) else: server_reply= "ok: " + str( system_retcode) + ": " + str(system_reply) if verbose_level > 0: print server_reply else: print "DEBUG do not execute os-cmd " , os_cmd return(system_retcode,server_reply) #--------------------------------------------------------------------------------------------- def lan_status(host_name): os_cmd_string = "ping -c 1 " + host_name unix_reply = unix_cmd(os_cmd_string) if unix_reply[0] ==0: server_reply = "host up / 1" else: server_reply = "ERROR host down / 0 / " + unix_reply[1] return(server_reply) #--------------------------------------------------------------------------------------------- def lan_wakeup(host_name): os_cmd_string = "wakeonlan " + host_name unix_reply = unix_cmd(os_cmd_string) wake_reply = unix_reply[1] if wake_reply.find('Sending magic') >-1: server_reply = "wake up send / 1" else: server_reply = "ERROR wake on lan failed / 0 / " + unix_reply[1] return(server_reply) #--------------------------------------------------------------------------------------------- def lan_shutdown(host_name): try: host_ip = socket.gethostbyname(host_name) except: return("ip address unkown -> please maintain /etc/hosts") host_data = lan_dict.get(host_name) if verbose_level > 3: print host_data host_os = host_data[0] host_user = host_data[1] host_pw = host_data[2] os_cmd_string = "net rpc SHUTDOWN -C 'NetIO shutdown' -f -I " + host_ip + " -U " +host_user +"%" +host_pw unix_reply = unix_cmd(os_cmd_string) if unix_reply[0] ==0: server_reply = "host shutdown succesfull / 1" else: server_reply = "ERROR shutdown failed " + unix_reply[1] sys.stderr.write(server_reply) return(server_reply) #--------------------------------------------------------------------------------------------- def lan_sleep(host_name): server_reply = unix_cmd("echo 'no clue what to do'") return(server_reply) #--------------------------------------------------------------------------------------------- def srvcmd_lan(server_cmd,client_words,client_args): # examples # "send", "Wohnz", "An" # "send", "Wohnz", "Aus" # "send", "Wohnz", "status" # "send", "Wohnz" if verbose_level > 2: print "++++ srvcmd_lan()" if verbose_level > 3: print "lan client_words : ", client_words print "lan client_args : ", client_args if (client_args < 2): server_reply = "not enougth arguments for command " + client_cmd print server_reply return (server_reply) # get name of light provided as second argument LanName = client_words[1] LanCmd = client_words[2] LanCmd = LanCmd.lower() if verbose_level > 2: print "Host:", LanName print "L.Cmd:", LanCmd # retrieve ID form dictionary LanID = lan_dict.get(LanName) if (None == LanID): print "Computer unknown : " , LanName server_reply = "Computer unknwon" return (server_reply) if verbose_level > 2: print "Der Computer " + LanName + " mit id " + str(LanID) + " wird angesprochen" if LanCmd == LanCmdOn: server_reply = lan_wakeup(LanName) elif LanCmd == LanCmdOff: server_reply = lan_shutdown(LanName) elif LanCmd == LanCmdStatus: server_reply = lan_status(LanName) else: server_reply = "unknown command: " + LanCmd sys.stderr.write(server_reply) return(server_reply) #--------------------------------------------------------------------------------------------- def srvcmd_timer(server_cmd,send433,client_words,client_args): # examples # "Timer", "Wohnz", "An 30" # "Timer", "Wohnz", "Stop" # "Timer", "Wohnz", "Status" global t, light_state, timer_state if verbose_level > 2: print "++++ srvcmd_timer()" print "timer client_words : ", client_words print "timer client_args : ", client_args if verbose_level > 2: print "srvcmd_timer()" server_reply="unkown command for timer" if (client_args < 3): server_reply = "not enougth arguments for command " + client_cmd print server_reply return (server_reply) # get name of light provided as second argument Light = client_words[1] LightCmd = client_words[2] LightCmd = LightCmd.lower() # convert to lower case, e.g. An -> an if verbose_level > 1: print "Light :", Light print "L.Cmd :", LightCmd print timer_state print timer_state[Light] timer_status = timer_state[Light] # timer_no = 1 if (LightCmd == LightCmdOn) or (LightCmd == LightCmdOff): if verbose_level > 2: print "establish timer, Mode ", timer_mode # when timer is running, stop timer # if timer[timer_no] == 1: if timer_status == 1: t.cancel # Mode 1: switch to [state] when timer starts and to ![state] when elapsed if (timer_mode == 1) or (timer_mode == '1'): if verbose_level > 2: print "timer mode 1 ... switch light to ", LightCmd srvcmd_light(oscmd_Light,send433,["Licht",client_words[1],LightCmd],3) if LightCmd == LightCmdOn: client_words[2]=LightCmdOff else: client_words[2]=LightCmdOn if verbose_level > 2: print "timer mode 1 ... new light cmd ", client_words[2] duration = int(client_words[3]) * time_multi client_light = ["Licht",client_words[1],client_words[2],client_words[3]] if verbose_level > 3: print client_light t = threading.Timer(duration, srvcmd_timcmd, [oscmd_Light,send433,client_light,3]) # t = threading.Timer(duration, srvcmd_light, [oscmd_Light,client_light,3]) # timer[timer_no]=1 # set flag that timer is running timer_state[Light] = 1 t.start() server_reply=str(duration) if LightCmd == LightCmdStop: if verbose_level > 0: print "stop timer" # if (timer[timer_no] == 0) or (timer[timer_no] == '0'): if (timer_status == 0) or (timer_status == '0'): server_reply="timer not running" else: # timer_no = 1 # timer[timer_no]=0 # set flag that timer is running timer_state[Light] = 0 server_reply="timer on hold / cancelled" t.cancel() if LightCmd == LightCmdStatus: if verbose_level > 2: print "timer status" # if (timer[timer_no] == 0) or (timer[timer_no] == '0'): if (timer_status == 0) or (timer_status == '0'): server_reply = "timer not running " else: server_reply = "timer is running " return(server_reply) #--------------------------------------------------------------------------------------------- # need this function in the middle to reset timer status def srvcmd_timcmd(server_cmd,send433,client_words,client_args): srvcmd_light(server_cmd,send433,client_words,client_args) timer_state[client_words[1]] = 0 # timer_no = 1 # timer[timer_no]=0 #--------------------------------------------------------------------------------------------- def srvcmd_light(server_cmd,send433,client_words,client_args): # examples # "send", "Wohnz", "An" # "send", "Wohnz", "Aus" # "send", "Wohnz", "status" # "send", "Wohnz" if verbose_level > 2: print "++++ srvcmd_light()" if verbose_level > 2: print "light client_words : ", client_words print "light client_args : ", client_args if (client_args < 2): server_reply = "not enougth arguments for command " + client_cmd print server_reply return (server_reply) # get name of light provided as second argument Light = client_words[1] LightCmd = client_words[2] LightCmd = LightCmd.lower() if verbose_level > 2: print "Light:", Light print "L.Cmd:", LightCmd # retrieve ID form dictionary LightID = light_dict.get(Light) if (None == LightID): print "Light unknown : " , Light server_reply = "Light unknwon" return (server_reply) if verbose_level > 2: print "Die Leuchte " + Light + " mit id " + str(LightID) + " wird angesprochen" if LightCmd == LightCmdOn: switch_light(server_cmd,send433,str(LightID),"1",Light) server_reply = LightCmdOn elif LightCmd == LightCmdOff: switch_light(server_cmd,send433,str(LightID),"0",Light) server_reply = LightCmdOff elif LightCmd == LightCmdStatus: server_reply = check_light(Light) else: server_reply = "unknown command: " + LightCmd sys.stderr.write(server_reply) return(server_reply) #--------------------------------------------------------------------------------------------- def switch_light(server_cmd,send433,LightID,State,LightName): # instead of os.popen subprocess could be used # subprocess.call([server_cmd, cmd_args]) global light_state if verbose_level > 2: print "++++ switch_light()" print "send433 :", send433 print "server_cmd:", server_cmd print "LightID :", LightID print "State :", State if (send433 == 1) or (send433 == '1'): LE = LightID.split(' ') cmd = server_cmd + " -k " + LE[0] + " -d " + LE[1]+ " -s " + State else: cmd = server_cmd + " " + LightID + " " + State # cmd = 'echo "Hello world!"' # to be used as test for checking popen if debug_level == 0: # OLD - process = os.popen(cmd) if verbose_level > 2: print "subprocess.Popen:", cmd process = subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) system_reply = process.communicate() # process.poll() poll response - but doe not wait for process to be finished process.wait() system_retcode = process.returncode if system_retcode: server_reply= "ERROR: " + str( system_retcode) + ": " + str(system_reply) else: server_reply= "ok: " + str( system_retcode) + ": " + str(system_reply) if verbose_level > 1: print server_reply else: print "DEBUG do not execute os-cmd " , cmd light_state[LightName]=State if verbose_level > 2: print light_state pickle.dump( light_state, open( pickle_file, "wb" ) ) return(0) #--------------------------------------------------------------------------------------------- def check_light(LightName): if verbose_level > 2: print "++++ check_light()" light_val = light_state[LightName] if verbose_level > 2: print "Licht" , LightName, " - Status: ", light_val if (light_val == 0) or (light_val == '0') : server_reply = LightName + " Aus / " + str(light_val) else: server_reply = LightName + " An / " + str(light_val) if verbose_level > 3: print light_val print server_reply return(server_reply) #--------------------------------------------------------------------------------------------- def read_sensor(Sensor): if verbose_level > 2: print "++++ read_sensor()" print "sensor:" , Sensor if debug_level == 0: # get 1-Wire id from dictionary sensor_slave = str(sensor_dict.get(Sensor)) # Open 1-wire slave file sensor_device = '/sys/bus/w1/devices/' + str(sensor_slave) + '/w1_slave' if verbose_level > 2: print "open: ", sensor_device try: file = open(sensor_device) filecontent = file.read() # Read content from 1-wire slave file stringvalue = filecontent.split("\n")[1].split(" ")[9] # Extract temperature string if stringvalue[0].find("YES") > 0: # 2nd try sys.stderr.write("read_sensor_ CRC error") time.sleep(0.5) # grace period filecontent = file.read() # Read content from 1-wire slave file stringvalue = filecontent.split("\n")[1].split(" ")[9] if stringvalue[0].find("YES") > 0: sys.stderr.write("read_sensor_ CRC error") temp = 999 else: temp = float(stringvalue[2:]) / 1000 else: temp = float(stringvalue[2:]) / 1000 # Convert temperature value file.close() # Close 1-wire slave file temp=str(temp) except IOError: print "PANIC read_sensor - Cannot find file >" + sensor_slave + "< in /sys/bus/w1/devices/" print "No sensor attached" sys.stderr.write( "check with > cat /sys/devices/w1_bus_master1/w1_master_slaves") temp=("Sensor not attached") else: # this is dummy function generating a random number # ony used for testing purposes temp = random.randrange(-10, 30, 2) + 0.3 temp = Sensor + " " + str(temp) return(temp) # exit function read_sensor #--------------------------------------------------------------------------------------------- class MyTCPHandler(SocketServer.BaseRequestHandler): """ The RequestHandler class for our server. It is instantiated once per connection to the server, and must override the handle() method to implement communication to the client. """ def handle(self): while 1: # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).strip() if not self.data: break client_ip = self.client_address[0] client_data = self.data if verbose_level >-1 : status = "################# client >" + client_ip + "< send >" + client_data + "<" print status log_buffer.append(status) client_words = client_data.split(' ') client_cmd = client_words[0] client_args = len(client_words) if verbose_level >2 : print "client command >", client_cmd, "< with ", client_args, " arguments" # translate client command into server task client_cmd = client_cmd.lower() # convert to lower case to avoid sensitivity server_cmd = str(server_dict.get(client_cmd)) # if command is not listed in dictionary, return value is None if "None" == server_cmd: print "ERROR: client requested unknown command ", client_cmd print "-> please check spelling" print "-> commands are defined in server_dict{}, valid commands:" print server_dict.keys() print server_reply = "my dear client, your command is unknown: " else: if verbose_level >2 : print "client requested valid command", client_cmd # default message - should be set depending on command server_reply = "server will now process your command " + server_cmd # Netio - SetUp # is sending "read commands" as a standard to poll status if ( "read" == client_cmd): # server_reply = "reply to netio std command " + client_cmd server_reply = 'listening' print server_reply # Netio - SetUp # Item Label # reads dict # interval 2000 if ( "dict" == client_cmd): server_reply= str(light_state) if ( "log" == client_cmd): buff = "server log:\n" # ascending: # for i in log_buffer.get(): #descending: for i in (max_log_entries-1,-1,-1): if str(i) != 'None': buff += str(i) + "\n" server_reply = buff print server_reply # NetIO - SetUp # Item Switch # onValue 1 # onText An # offText Aus # onSend Licht Wohnz An # offSend Licht Wohnz Aus # reads Licht Wohnz Status # parseResponse \d+ # formatResponse {0} if ( "licht" == client_cmd): server_reply = srvcmd_light(server_cmd,0,client_words,client_args) if ( "licht2" == client_cmd): server_reply = srvcmd_light(server_cmd,1,client_words,client_args) # NetIO - SetUp # Item Switch # onSend Timer Wohnz An 30 # offSend Timer Wohnz Stop # reads Timer Wohnz if ( "timer" == client_cmd): server_reply = srvcmd_timer(server_cmd,0,client_words,client_args) # NetIO - SetUp # Item Label # reads temp [Sensor Name] # interval 2000 # parseResponse \d+ # formatResponse {0},{1}°C if ( "temp" == client_cmd): Sensor = client_words[1] # print "die Temperatur wird vom 1-Wire Sensor oder aus der DB gelesen" server_reply = read_sensor(Sensor) # NetIO - SetUp # Item Label # onSend Linux [Sensor Name] if ( "linux" == client_cmd): server_reply = srvcmd_linux(server_cmd,client_words,client_args) # NetIO - SetUp # Item Label # onSend Lan [Host Name] if ( "lan" == client_cmd): server_reply = srvcmd_lan(server_cmd,client_words,client_args) if ( "wetter" == client_cmd): server_reply = srvcmd_weather(server_cmd,client_words,client_args) # NetIO - SetUp # Item Label # reads System CPU Temp if ( "system" == client_cmd): server_reply = systemInfo(server_cmd,client_words,client_args) # NetIO - SetUp # Item Button # onSend gpio set gpio7 1 server_reply = srvcmd_led(server_cmd,client_words,client_args) # send feedback to client if verbose_level >1: print "server reply: " , server_reply log_buffer.append(server_reply) self.request.sendall(server_reply) #------------------------------------------------------------------------------------------------------ def srvcmd_linux(server_cmd,client_words,client_args): # examples # "Linux", "date" # "Linux", "pwd" system_cmd = [] # print client_words # print client_args system_cmd.append(client_words[1]) if client_args >2: system_arg = client_words[2] system_cmd.append(system_arg) print system_cmd if verbose_level > 2: print "++++ srvcmd_linux()" print "command:" , system_cmd if debug_level == 0: # http://jimmyg.org/blog/2009/working-with-python-subprocess.html process = subprocess.Popen(system_cmd, shell=False,stdout=subprocess.PIPE, stderr=subprocess.PIPE) system_reply = process.communicate() # system_reply = process.stdout.readline() print system_reply # process.poll() poll response - but doe not wait for process to be finished process.wait() system_retcode = process.returncode if system_retcode: server_reply= "ERROR: " + str( system_retcode) + ": " + str(system_reply) else: server_reply= "ok: " + str( system_retcode) + ": " + str(system_reply) print server_reply else: # this is dummy function generating a feedback # ony used for testing purposes server_reply = "test test" return(server_reply) # exit function read_sensor #------------------------------------------------------------------------------------------------------ def displayText(text, size, line, color, clearScreen): """Used to display text to the screen. displayText is only configured to display two lines on the TFT. Only clear screen when writing the first line""" if clearScreen: screen.fill((0, 0, 0)) font = pygame.font.Font(None, size) text = font.render(text, 0, color) textRotated = pygame.transform.rotate(text, -90) textpos = textRotated.get_rect() textpos.centery = 80 if line == 1: textpos.centerx = 90 screen.blit(textRotated,textpos) elif line == 2: textpos.centerx = 40 screen.blit(textRotated,textpos) print "tft: ", text #--------------------------------------------------------------------------------------------- def server_init(mode): global t, light_state, timer_state if verbose_level > 2: print "++++ server_init()" status = "init light status" print status log_buffer.append(status) # get number of entries in dictionary light_count = len(light_dict) # print "No. of lights: ", light_count # create light state array lights=light_dict.keys() # print lights for x in range(0,light_count): # print lights[x] light_state[lights[x]] = 0 timer_state[lights[x]] = 0 if verbose_level >2 : print "lights state:\n" , light_state print "timer state:\n" , timer_state # a) power down all light devices if(mode == "reset"): x1 = ["Licht","xx",LightCmdOff,""] server_cmd = str(server_dict.get("licht")) for x in range(0,light_count): light = lights[x] print "send reset light", light x1[1] = light if verbose_level >1: print x1 # srvcmd_light(server_cmd,0,clients_words,client_args) srvcmd_light(server_cmd,0,x1,4) elif(mode == "lightson"): x1 = ["Licht","xx",LightCmdOn,""] server_cmd = str(server_dict.get("licht")) for x in range(0,light_count): light = lights[x] print "send on to light", light x1[1] = light if verbose_level >1: print x1 # srvcmd_light(server_cmd,0,clients_words,client_args) srvcmd_light(server_cmd,0,x1,4) else: print "read state from file" try: light_state = pickle.load( open( pickle_file, "rb" ) ) print "lights state:" , light_state except IOError: print "Warning: file ", pickle_file, "does not exist, assuming all lights are off" return (0) #--------------------------------------------------------------------------------------------- if __name__ == "__main__": # example # netio_server.py # start server with default parameters # netio_server.py -h # help : show brief description of options # netio_server.py -r # reset: switch off all lights when starting server and create new pickle file # netio_server.py -r -v 3 -H 192.168.178.21 -P 5431 parser = argparse.ArgumentParser(description='server for NetIO client by Thomas Hoeser / 2013') parser.add_argument("-r", "--reset", action='store_const', dest='reset', const='value-to-store', help="switch off all lights when starting server and create new pickle file") parser.add_argument("-l", "--lightson", action='store_const', dest='lightson', const='value-to-store', help="switch on all lights when starting server and create new pickle file") parser.add_argument("-n", "--noserver", action='store_const', dest='noserver', const='value-to-store', help="do not start server, stop after init") parser.add_argument("-t", "--time", action='store_const', dest='time', const='value-to-store', help="1: value are seconds, 60: value should be minutes") parser.add_argument("-v", "--verbose", default=False, dest='verbose', help="increase output verbosity", type=int) parser.add_argument("-d", "--debug", action='store_const', dest='debug', const='value-to-store', help="debug mode - will prevent executing send command or reading 1-wire sensor") parser.add_argument("-H", "--Host", default=False, dest='host', help="define Host", type=str) parser.add_argument("-P", "--Port", default=False, dest='port', help="define Port", type=int) parser.add_argument("-s", "--show", action='store_const', dest='show', const='value-to-store', help="show configuration") parser.add_argument('--version', action='version', version='%(prog)s 0.2') args = parser.parse_args() if args.verbose : verbose_level = args.verbose if args.time : time_multi = args.time if args.reset : server_init_mode = "reset" if args.lightson: server_init_mode = "lightson" if args.debug : debug_level = 1 if args.port : PORT = args.port if args.host : HOST = args.host if args.show : print "Host : " , HOST print "PORT : " , PORT print "pickle file : " , pickle_file print "server dict : " print server_dict print "sensor dict : " print sensor_dict print "light dict : " print light_dict sys.exit(1) server_init(server_init_mode) #reset used to switch off all lights if args.noserver : sys.exit(0) try: # Create the server, binding to localhost on port 9999 print "create socket server" server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler) # Activate the server; this will keep running until you # interrupt the program with Ctrl-C print "server established on host", HOST, "and port", PORT server.serve_forever() except socket.error, msg: sys.stderr.write("[ERROR] %s\n" % msg[1]) sys.exit(1)
Für Neueinsteiger auch noch meine Konfigurationsdatei, die auf Eure Bedürfnisse angepaßt werden muss.
Code
Alles anzeigen# -*- coding: utf-8 -*- # ----------------------------------------------------------------------------------------------- # use this section to set the parameters for your setup # ----------------------------------------------------------------------------------------------- HOST = '' # PORT = 54321 # enter port number # dictionary with for send command: [group code] [device] light_dict = { "Wohnz" : "00101 1", "Flur1" : "00101 2", "Flur2" : "11111 3", "Garage" : "11111 4", "Black" : "11111 5", "Wohnzimmer" : "10011 1", "Flur" : "10011 2", "Kueche" : "10011 3", "Brunnen" : "10011 4", "Fernseher" : "10011 5", "Kinderzimmer" : "10001 1" } # dictionary with for 1-wire sensors: [sensor name] [1-Wire device] sensor_dict = { "Wohnzimmer": "28-00000487bb70", "Terrasse" : "28-000004881dd5", "Wintergarten" : "28-000004885b83", "Aussen" : "28-000004881b78", "WW_Speicher" : "28-00000487e239", "Ruecklauf" : "28-000004884121", "Vorlauf" : "28-00000487ae73", "Pool" : "28-000004be1337" } openweather_path = "/home/pi" # directory where JSON files are located time_multi = 1 # 1: value are seconds, 60: value should be minutes debug_level = 0 # 1 will prevent executing send command or reading 1-wire sensor # verbose 1: display client commands // 2: 1 + display server reply // 2 + debug messages verbose_level = 1 # this is the file where the status is stored pickle_file = "433_status.p" server_init_mode = "resetno" # read pickle file , no send command # server_init_mode = "reset" # use send command to switch off all lights when server is started # this is the standard command to switch the ELRO 433 MHz devices oscmd_Light = "sudo /home/pi/raspberry-remote/./send " # sudo /home/pi/raspberry-remote/./send 00101 5 0 # an alternative command to switch some other 433 MHz devices oscmd_Light2 = "sudo /home/pi/433/./433send " # sudo /home/pi/433/./433send2 -k 00101 -d 5 -s 0 # Timer: # Mode 0: switch to [state] when timer elapsed # Mode 1: switch to [state] when timer starts and to ![state] when elapsed timer_mode = 1 t = 0 # lan computers defined in /etc/host and /etc/ethers # pc-name : [operating system, username, password] lan_dict = { "raspi1" : ["linux","pi","raspberry"], "raspi2" : ["linux","pi","raspberry"], "fritzi" : ["linux","pi","raspberry"], "mahjong": ["win7","shutdown","raspdx"], "avatar" : ["win8","shutdown","raspdx"], "phoenix": ["win8","shutdown","raspdx"] } # this is the file where the status is stored log_level = 0 # 0: no log; 1: save messages to logifle log_file = "netio_logfile.txt"
-
Hat jetzt jemand eine ahnung wie ich python scripts über den netioserver von thomas starten kann? Linux 'x' funzt nicht ..
-
-
Also ich habe nochmals genau nach anleitung gemacht die Ansteuerung der LED klappt und den Status anzeigen über den Befehl:
klappt auch.Über Netio klappt die Ansteuerung auch nur sobald ich Status in den Button mit einbringen dann spinnt alles die Staus Lampen von 433MHZ ansteuerung gehen an/aus dann die Timer funktion zeig unsinniges zeug siehe Bilder
Vll kann mir einer Helfen??
Die Configs von Netio sind auch bebildert....
Grüße
Für den Zugriff auf GPIO gibt man in Netio ein read Kommando ein:GPIO muss auf Systemseite aber entsprechend vorbereitet sein.
Einmalig auf dem System die [font="Calibri"]Rechte ändern, damit man sudo nicht mehr benutzen muss.[/font]
Nach Systemstart, muss der PIN vorbereitet werden:
Der Lesebefehl sieht auf der Shell wie folgt aus
Ein Doku für GPIO mit Beispielen gibt es auch hier: klick
Bei der Übung habe ich noch einen Fehler im netio_server entdeckt. Die funktion srvcmd_gpio wurde gar nicht aufgerufen. Ich habe auch noch ein exception handling eingefügt.
Die Version 2.0 liegt jetzt auf github
[font="Calibri"]Clone complete project to local raspberry[/font]
[font="Calibri"]cd; mkdir -p git; cd git[/font]
[font="Calibri"]git clone git://http://github.com/ThomasH-W/netio_server[/font]
[font="Calibri"] [/font]
[font="Calibri"]Update Project files by pulling new files[/font]
[font="Calibri"]cd ~/git/netio_server[/font]
[font="Calibri"]git pull[/font] -
Hallo,
habe heute das Tutorial von der Seite 1 abgearbeitet.
Soweit funktioniet auch alles bis auf die Wetter Abfrage.
Ich bekomme folgende Meldung wenn ich das App starte.
Hat jemand von euch eine Idee?PANIC: cannot open file: /home/pi/ow_wiehl_cur.json################# client >71.11.99.11< send >Wetter Berlin tempmax<
Temp Max: 21 Grad | 21 | 19 | 15 | 14 | 13 | 16 | 18Danke
bibo09 -
- Offizieller Beitrag
Hei,
schön das alles soweit klappt!
Das liegt daran, dass du keine Jason Datei hast.
Irgendwo hier steht wie diese Aussehen muss. Eventuell kann dir auch einer hier helfen, der es vor kurzem erst selber gesucht hat.Ich werde bei Zeiten eine Beispiel Json vorne im ersten Beitrag anhängen. Bis dahin, viel erfolg
-
Die json.Dateien for.json und cur.json wurden aber im Ordner home/pi angelegt und per Crontab alle 10 min aktualisiert. :s
-
- Offizieller Beitrag
Ja, aber:
cannot open file: /home/pi/ow_wiehl_cur.jsonDie wohl nicht
-
Stimmt
Aber wie wird die Datei angelegt?
Die anderen wurden ja automatisch hinzugefügt. -
- Offizieller Beitrag
Ja,
mit "sudo nano ow_wiehl_cur.json". Die Frage ist, was dort hinein muss
Und das steht irgendwo auf den 53 Seiten
LG
-
Hi,
habe leider nichts auf den Seiten finden können.
Die Frage ist ob die ow_wiehl_cur.json automatisch hinzugefügt wird
und was deren Inhalt ist.Kann mir bitte einer sagen was in der ow_wiehl_cur.json reingehört?
Gruß und Danke
bibo -
- Offizieller Beitrag
Ich bilde mir ein das eine Möglichkeit gibt aus einem der beiliegenden python scripte die die Datei zu generieren. Btw. die ow_wiehl macht natürlich nur Sinn wenn man in Wiehl wohnt. Sonst heisst die ow_STADT...
Inhalt sind die Wetterdaten der jeweiligen Stadt, welche in der config angegeben ist (glaub ich).
Notfalls schau ich heut abend mal genau nach.
-
Ein eigenständiges Modul liest die Daten von openweather und schriebt dies in eine JSON Datei.
Der server liest diese Datei und wandelt Formate um.Den Client "openweather_client.py "über crontab starten. Als Parameter wird der Ortsname mitgegeben.
Folgende Zeilen in crontab einfügen (den Pfad zum client entsprechend anpassen):
-
Bei mir steht folgender Error in der crontab_ow_client.log:
File "/home/pi/RPi.GPIO-0.1.0/openweather_client.py", line 57
req = urllib2.Request(ow_url_cur)
^
IndentationError: unindent does not match any outer indentation levelGruss
-
Jetzt mitmachen!
Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!