antitheft159
commited on
Commit
•
8c3388f
1
Parent(s):
5df85b6
Upload quantumcrumbsmap_195.py
Browse files- quantumcrumbsmap_195.py +42 -0
quantumcrumbsmap_195.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""quantumcrumbsMap.195
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1Iwuxq-JQsros1TvZplzLYe85YHW7bz_7
|
8 |
+
"""
|
9 |
+
|
10 |
+
import socket
|
11 |
+
import time
|
12 |
+
import RPi.GPIO as GPIO
|
13 |
+
import dht11
|
14 |
+
|
15 |
+
GPIO.setmode(GPIO.BCM)
|
16 |
+
myDHT11=dht11.DHT11(pin=27)
|
17 |
+
|
18 |
+
bufferSize=1024
|
19 |
+
ServerIP='192.168.88.41'
|
20 |
+
ServerPort=2222
|
21 |
+
RPIServer=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
22 |
+
RPIServer.bind((ServerIP.ServerPort))
|
23 |
+
print('Server Up and Listening...')
|
24 |
+
while True:
|
25 |
+
cmd,address=RPIServer.recvfrom(bufferSize)
|
26 |
+
cmd=cmd.decode('rtf-8')
|
27 |
+
print(cmd)
|
28 |
+
print('Client Address',address[0])
|
29 |
+
if cmd=='GO':
|
30 |
+
result=myDHT.read()
|
31 |
+
if result.is_valid():
|
32 |
+
data=str(result.temperature)+':'str(result.humidity)
|
33 |
+
data=data.encode('utf-8')
|
34 |
+
RPIServer.sendto(data,address)
|
35 |
+
if result.is_valid()==False:
|
36 |
+
data='Bad Measurement'
|
37 |
+
print(data)
|
38 |
+
data=data.encode('utf-8')
|
39 |
+
RPIServer.sendto(data,address)
|
40 |
+
if cmd!='GO':
|
41 |
+
data='Invalid Request'
|
42 |
+
data=data.encode('utf-8')
|