로컬로 완벽하게 작동하는 MQTT 가입자 용 Python 스크립트를 작성했습니다.Google 애플리케이션 엔진에서 Python으로 작성된 MQTT 가입자 스크립트를 실행하는 방법
파이썬 가입자 스크립트
import paho.mqtt.client as mqtt
import os,json
filePath = "logs.csv"
def initiateFile():
if (os.path.exists(filePath) == False):
fileObj = open(filePath, "w")
fileObj.write("Label,x,y,z\n")
def readFile():
data = open(filePath,'r').read()
return data
def decodeJson(jsonString):
jsonObject = json.loads(jsonString)
label = jsonObject.keys()[0]
x = jsonObject[label]['x']
y = jsonObject[label]['y']
z = jsonObject[label]['z']
return label.encode("utf-8")+","+x+","+y+","+z;
def writeInFile(newData):
oldData = readFile()
fileObj = open(filePath, "w")
fileObj.write(oldData+newData+"\n")
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc)+" "+str(client))
client.subscribe("sensors/test")
initiateFile()
def on_message(client, userdata, msg):
print msg.payload
writeInFile(decodeJson(msg.payload))
def on_disconnect(client, userdata, rc):
print("Disconnect, reason: " + str(rc))
print("Disconnect, reason: " + str(client))
client = mqtt.Client()
client.username_pw_set(username, password)
client.connect(broker,port)
client.on_connect = on_connect
client.on_message = on_message
client.loop_forever()
client.on_disconnect = on_disconnect
하지만 구글의 클라우드에 배포하려고 할 때, 나는 "ImportError를 : 아니오 모듈의 이름 paho.mqtt.client"가지고 오류가 발생했습니다.
은 그럼 클라우드에 PAHO - MQTT는***OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.0.dist-info'***
쉘 다음과 같은 솔루션을 시도했지만 설치 PIP) 오류
1)
2. 애플리케이션 제목을
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
libraries:
- name: paho-mqtt
version: "1.3.0"
***ERROR: (gcloud.app.deploy) An error occurred while parsing file: [C:\Users\uni5p_000\Desktop\RMIT_Studies\Sem_1\Cloud_Computing\Practical\GOOGLE\python-docs-samples\appengine\standard\hello_world\app.yaml]
the library "paho-mqtt" is not supported
in "C:\Users\uni5p_000\Desktop\RMIT_Studies\Sem_1\Cloud_Computing\Practical\GOOGLE\python-docs-samples\appengine\standard\hello_world\app.yaml", line 11, column 19***
에 PAHO - MQTT 라이브러리를 선언있어
지금 진행 하시겠습니까?
가능한 복제 [구글 앱 엔진의 타사 파이썬 라이브러리를 포함하는 방법? (https://stackoverflow.com/questions/14850853/how-to-include-third-party-python-libraries- in-google-app-engine) – hardillb
표준 환경에서 실행하는 경우 설치 및 소켓을 분류해도 실제로 작동하지 않습니다. 표준 환경은 장기 실행 쿼리를 지원하지 않습니다. 전면 방향 요청은 1 분 동안 만 실행되고 작업 대기열은 10 분으로 제한됩니다. 나는 당신이 cron에 의해 트리거 된 각 요청에 끊임없이 연결/연결 해제 할 수 있다고 가정합니다. –