반응형
힘들게 일한다. 어려운 일도 아닌데, 시간만 보내고. 앞으로 그런일 없도록 하자.
소스코드와 사진
서버 Test 코드 실행은 $sudo python server.py
#-*- coding:utf-8 -*-
from socket import *
serverSock = socket(AF_INET, SOCK_STREAM)
serverSock.bind(('', 8080))
serverSock.listen(1)
connectionSock, addr = serverSock.accept()
print(str(addr), '에서 접속이 확인되었습니다.')
while True:
data = connectionSock.recv(1024)
print('받은 데이터 : ', data.decode('utf-8'))
#connectionSock.send('I am a server.'.encode('utf-8'))
#print('메시지를 보냈습니다.')
클라이언트 테스트코드 실행은 $sudo python testblescan.py
#-*- coding: utf-8 -*-
# test BLE Scanning software
# girin 9/30/2019
import RPi.GPIO as GPIO
import time
from socket import *
import blescan
import sys
import bluetooth._bluetooth as bluez
clientSock = socket(AF_INET, SOCK_STREAM)
clientSock.connect(('127.0.0.1', 8080))
print('연결 확인 됐습니다.')
dev_id = 1 #0
#pi@raspberrypi:~ $ hcitool dev
#Devices:
# hci1 B8:27:EB:3F:20:99
# hci0 00:15:83:6B:F6:6D
try:
sock = bluez.hci_open_dev(dev_id)
print ("ble thread started")
except:
print ("error accessing bluetooth device...")
sys.exit(1)
blescan.hci_le_set_scan_parameters(sock)
blescan.hci_enable_le_scan(sock)
CollectedBeaconAddress = []
FindBeacon = []
StoredBeacon = []
NumofFindBeacon = len(FindBeacon)
NumofStoredBeacon = len(StoredBeacon)
print(NumofFindBeacon)
print(NumofStoredBeacon)
dub_list = []
before_Pir = 0;
before_Motion = 0
while True:
returnedList = blescan.parse_events(sock, 20) #10, 100, 20
#여기서 맥주소만 뽑아서 맥주소를 상대로
del dub_list[:]
for beacon in returnedList:
origin_macaddress = beacon.split(',')[0]
split_macaddress = origin_macaddress.split(':')
mac_address= split_macaddress[0]+split_macaddress[1]+split_macaddress[2]+split_macaddress[3]+split_macaddress[4]+split_macaddress[5]
dub_list.append(mac_address)
#수집된거중 중복제거
del CollectedBeaconAddress[:]
CollectedBeaconAddress = list(set(dub_list))
print (CollectedBeaconAddress)
#print (StoredBeacon)
print ("----------")
for beacon in CollectedBeaconAddress:
#print (beacon)
#print(beacon.split(',')[0])
#origin_macaddress = beacon.split(',')[0]
#split_macaddress = origin_macaddress.split(':')
#mac_address= split_macaddress[0]+split_macaddress[1]+split_macaddress[2]+split_macaddress[3]+split_macaddress[4]+split_macaddress[5]
#리스트만들어 두고 추가 삭제를 자유롭게 보내는 것도 자유롭게
#1.맥어드레스를 저장된 어드레스와 비교해서 저장하고 있다면 통과/2.없으면 집어넣고 발견됐다고 메세지 송신/리스트에 있는데 없으면 없다고 메시지 만들어 송신
if beacon in StoredBeacon:
#이미 있으므로 패스
#print(StoredBeacon)
pass
else:
#없으니 저장하고 전송하기
print(beacon)
StoredBeacon.append(beacon)
clientSock.send('E5E5E5E5E5E5E5E5'+'0001'+'01'+ beacon + 'ffff')
print('in 메시지를 전송했습니다.')
#print (CollectedBeaconAddress)
for outbeacon in StoredBeacon:
if outbeacon in CollectedBeaconAddress:
pass
else:
print(outbeacon)
StoredBeacon.remove(outbeacon)
clientSock.send('E5E5E5E5E5E5E5E5'+'0001'+'00'+ outbeacon + 'ffff')
print('out 메시지를 전송했습니다.')
#센서데이터 전송
작업 사진은 아직 완료 되지 않았다. 아흑!








반응형
'개발자 > Raspberry Pi3' 카테고리의 다른 글
| 한국산업기술 대학교 "라즈베리파이를 활용한 IoT 프로그래밍", 수강 필수! (0) | 2019.11.27 |
|---|---|
| 가장 간단한 라즈베리파이 개발 환경 구성할 때 주의할 점 (0) | 2019.10.12 |
| 라즈베리파이를 AP모드로 변경시 에러 처리 (0) | 2019.10.09 |
| 라즈베리파이3 B+ 데이터베이스 설치 실행 문제, error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or director (1) | 2019.10.09 |
| 파이선 소켓 프로그램 1 - 서버와 클라이언트 (1) | 2019.09.04 |
| 자동 실행 /etc/rc.local 에서 실행이 잘 안되는 경우 (0) | 2019.08.29 |
| RASPBERRY PI 3 B+ 블루투스 스캐너 설정 (0) | 2019.08.05 |
| 라즈베리파이를 사용할 때 알아야 할 것들. (0) | 2019.08.05 |
취업, 창업의 막막함, 외주 관리, 제품 부재!
당신의 고민은 무엇입니까? 현실과 동떨어진 교육, 실패만 반복하는 외주 계약,
아이디어는 있지만 구현할 기술이 없는 막막함.
우리는 알고 있습니다. 문제의 원인은 '명확한 학습, 실전 경험과 신뢰할 수 있는 기술력의 부재'에서 시작됩니다.
이제 고민을 멈추고, 캐어랩을 만나세요!
코딩(펌웨어), 전자부품과 디지털 회로설계, PCB 설계 제작, 고객(시장/수출) 발굴과 마케팅 전략으로 당신을 지원합니다.
제품 설계의 고수는 성공이 만든 게 아니라 실패가 만듭니다. 아이디어를 양산 가능한 제품으로!
귀사의 제품을 만드세요. 교육과 개발 실적으로 신뢰할 수 있는 파트너를 확보하세요.
캐어랩