2

그래서 tryna는 Rpi를 통해 Z 파 센서에서 데이터를 읽는 python 스크립트를 실행하고 pi에 crontab을 사용하여 python 스크립트가 매분마다 실행되고 저장하도록 설정했습니다. 그것은 텍스트 파일에. 그런 다음 테이블 형식으로 푸른 구름 저장소에 데이터를 보내는 또 다른 python 스크립트가 있습니다. 문제는 테이블을 만들지 만 오류 "이 XML 파일에 연결된 스타일 정보가없는 것 같습니다."입니다. 필자는 그것을 알아 내려고 노력했지만 내가 볼 수있는 것은 잘못된 것입니다. 방법이있다 azure에서 테이블을 만들 파이썬 스크립트

클라우드

from azure.storage import TableService, Entity 
from datetime import datetime 
import socket 

ac_name = 'account name' 
#you will have to use your own azure account 
primary_key = 'use your key' 
table_name = 'Readings' 

current_temperature = 0 

def get_connection_string_and_create_table(): 
    global table_service 
    table_service = TableService(account_name = ac_name,account_key=primary_key) 
    #table_service.delete_table(table_name = table_name) #TO BE USED IF THE TABLE NEEDS TO BE DELETED 
    table_service.create_table(table=table_name) 

def insert_data(): 
    reading = create_entity() 
    try: 
     if check_internet_available(): 
      table_service.insert_entity(table_name = table_name,entity = reading) 
      return True 
    except Exception, e: 
     return False 


def create_entity(): 

    """ 
    - Creates the data block that would be sent to the cloud, named as Entity 
    """ 

    time_now = datetime.strftime(datetime.now(),'%d-%m-%Y %H:%M:%S') 
    print('Date time is {0}'.format(time_now)) 
    reading = Entity() 
    reading.PartitionKey = 'Room1' 
    reading.RowKey = time_now 
    reading.Timestamp = datetime.now() 
    reading.Temperature = str(current_temperature) 
    return reading 

def initialize_azure(): 
    get_connection_string_and_create_table() 

def send_data_to_cloud(temperature): 
    global current_temperature 
    current_temperature = temperature 
    sent_success = insert_data() 
    print temperature 
    print sent_success 
    return sent_success 


def check_internet_available(): 

    """ 
    - Checks internet availability, the data will be sent to cloud 
     only if there is an active internet connection 

     remote_server = 'www.google.com' 
    try: 
     host = socket.gethostbyname(remote_server) 
     s = socket.create_connection((host,80),2) 
     return True 
    except: 
     pass 
    return False 


if __name__ == '__main__': 

    get_connection_string_and_create_table() 
    f = open('Meter.txt', 'r') 
    send_data_to_cloud(f.readline()) 

에 데이터를 전송하는 파이썬 스크립트입니다 그리고 이것이 API

import urllib2 
import json 
import requests 
import time 
import json 

class EnergyConsumptionControl: 

    # Class constructor 
    def __init__(self): 
     # Global Variables 
     self.energyMeterDeviceUrl = "http://IpaddressofyourRpi" 
     self.session = requests.Session() 
     # Logging in 
     self.Login() 


    def ActivateDevice(self, deviceID): 
     energyMeterDeviceSwitchOn = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].SwitchBinary.Set(255)" 
     response = self.SendGetCommand(energyMeterDeviceSwitchOn) # Command to turn device on 
     return [response] 


    def DeactivateDevice(self, deviceID): 
     energyMeterDeviceSwitchOff = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].SwitchBinary.Set(0)" 
     response = self.SendGetCommand(energyMeterDeviceSwitchOff) # Command to turn device off 
     return [response] 


    def GetDeviceState(self, deviceID): 
     # Call the Get() function to update the SwitchBinary data 
     energyMeterDeviceSwitchGet = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].SwitchBinary.Get()" 
     response = self.SendGetCommand(energyMeterDeviceSwitchGet) 
     # Call to return the SwitchBinary JSON object 
     energyMeterDeviceSwitchGet = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].SwitchBinary" 
     response = self.SendGetDeviceStateCommand(energyMeterDeviceSwitchGet) 
     return response 


    # def GetDeviceMeter(self, deviceID): 
    #  # Refreshing server-side information on the Meter through device interrogation 
    #  energyMeterDeviceMeterGetVals = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].Meter.Get()" 
    #  response = self.SendGetCommand(energyMeterDeviceMeterGetVals) 
    #  # Retrieving the JSON of all Meter related data 
    #  energyMeterDeviceMeterGet = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].Meter" 
    #  response = self.GetMeterWattage(energyMeterDeviceMeterGet) 
    #  return [response] 

    def GetDeviceEnergyConsumption(self, deviceID): 
     # Refreshing server-side information on the Meter through device interrogation 
     energyMeterDeviceMeterRefreshVals = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].Meter" 
     response = self.SendGetCommand(energyMeterDeviceMeterRefreshVals) 

     # Retrieving the JSON of all Meter related data 
     energyMeterDeviceMeterGetVals = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].Meter" 
     energyConsumption = self.GetMeterConsumption(energyMeterDeviceMeterGetVals) 

     response = self.ResetDeviceMeter(deviceID) 
     return energyConsumption 
def GetDeviceEnergyWattage(self, deviceID): 
     # Refreshing server-side information on the Meter through device interrogation 
     energyMeterDeviceMeterRefreshVals = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].Meter.Get()" 
     response = self.SendGetCommand(energyMeterDeviceMeterRefreshVals) 

     # Retrieving the JSON of all Meter related data 
     energyMeterDeviceMeterGetVals = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].Meter" 
     energyWattage = self.GetMeterWattage(energyMeterDeviceMeterGetVals) 
     print energyWattage 
     return energyWattage 


    def ResetDeviceMeter(self, deviceID): 
     energyMeterDeviceMeterReset = ":8083/ZWaveAPI/Run/devices[" + str(deviceID) + "].Meter.Reset(255)" 
     response = self.SendPostCommand(energyMeterDeviceMeterReset) # Command to reset device meter value 
     return [response] 


    def Login(self): 
     data = { 
      "form": True, 
      "login": "admin", 
      "password": "#password", 
      "keepme": False, 
      "default_ui": 1 
     } 

     # Authenticating 
     headers = {'Content-Type': 'application/json'} 
     response = self.session.post(self.energyMeterDeviceUrl + ':8083/ZAutomation/api/v1/login', headers=headers, 
           data=json.dumps(data)) 

    # Generic function to send GET commands to individual Z-Wave devices 
    def SendGetCommand(self, command): 
     status = self.session.get(self.energyMeterDeviceUrl + command) 
     print status 
     print status.text 
     return [status] 

    # Generic function to send POST commands to individual Z-Wave devices 
    def SendPostCommand(self, command): 
     status = self.session.post(self.energyMeterDeviceUrl + command) 
     print status 
     print status.text 
     return [status] 

    def GetMeterWattage(self, command): 
     status = self.session.get(self.energyMeterDeviceUrl + command) 
     json_data = json.loads(status.text) 
     # Parsing the JSON data to get just the energy wattage (W) 
     return json_data['data']['2']['val']['value'] 


    def GetMeterConsumption(self, command): 
     status = self.session.get(self.energyMeterDeviceUrl + command) 
     json_data = json.loads(status.text) 
     # Parsing the JSON data to get just the energy consumption (kWh) 
     return json_data['data']['0']['val']['value'] 
def SendGetDeviceStateCommand(self, command): 
     status = self.session.get(self.energyMeterDeviceUrl + command) 
     json_data = json.loads(status.text) 
     # Parsing the JSON data to get just the 'level' 
     return int(json_data['data']['level']['value']) 


control = EnergyConsumptionControl() 
response = control.GetDeviceEnergyConsumption(8) 
print response 


control = EnergyConsumptionControl() 
response = control.ActivateDevice(8) 
print response 

에서 HTTP 요청을 통해 데이터를 읽는 스크립트에 중 두 데이터를 결합하여 데이터를 호출하고 클라우드로 보냅니다. 어떻게 오류를 해결할 수 있습니까? 메시지

+0

당신은 찾을 별도로 코드를 테스트 할 수있는 곳에서의 문제, 코드를 업로드하거나 코드를 다운로드. 클라우드는 다운로드 파일 내용을보고 표준 XML 파일인지 여부를 검사합니다. 이 URL http://stackoverflow.com/questions/14804452/opening-facelets-page-errors-with-this-xml-file-does-not-appear-to-have-any-sty가 유용 할 수 있습니다. – johnny

답변