sdasd

Dependencies:   BLE_API mbed nRF51822

Fork of MEDRON_SNIFFER_ABCD-KIMLIKLI-OLANLARI-TARAMA-YAPAR_30062016 by HAKAN AYDIN

Committer:
hknydn
Date:
Fri Mar 18 15:30:12 2016 +0000
Revision:
12:f4b869da449c
Parent:
11:16f67d5752e1
Child:
13:5f87b9cdeb6f
Sadece bize ait mac adresini bulur ve listeler

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 0:332983584a9c 1 /* mbed Microcontroller Library
rgrover1 0:332983584a9c 2 * Copyright (c) 2006-2015 ARM Limited
rgrover1 0:332983584a9c 3 *
rgrover1 0:332983584a9c 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 0:332983584a9c 5 * you may not use this file except in compliance with the License.
rgrover1 0:332983584a9c 6 * You may obtain a copy of the License at
rgrover1 0:332983584a9c 7 *
rgrover1 0:332983584a9c 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 0:332983584a9c 9 *
rgrover1 0:332983584a9c 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 0:332983584a9c 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 0:332983584a9c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 0:332983584a9c 13 * See the License for the specific language governing permissions and
rgrover1 0:332983584a9c 14 * limitations under the License.
rgrover1 0:332983584a9c 15 */
rgrover1 0:332983584a9c 16
rgrover1 0:332983584a9c 17 #include "mbed.h"
rgrover1 9:69a2ad0bcdb7 18 #include "toolchain.h"
rgrover1 9:69a2ad0bcdb7 19 #include "ble/BLE.h"
hknydn 12:f4b869da449c 20
hknydn 12:f4b869da449c 21 //ABCD bir kimlik olarak belirlenir ve şifre vazifsedi görür herhangi bir bluetooth modülü ABCD içerirse burada görülecektir.
sunsmile2015 7:91324daa3bfa 22
rgrover1 9:69a2ad0bcdb7 23 DigitalOut alivenessLED(LED1, 1);
andresag 11:16f67d5752e1 24 Ticker ticker;
hknydn 12:f4b869da449c 25 Serial pc(TX_PIN_NUMBER, RX_PIN_NUMBER);
rgrover1 0:332983584a9c 26
rgrover1 0:332983584a9c 27 void periodicCallback(void)
rgrover1 0:332983584a9c 28 {
rgrover1 9:69a2ad0bcdb7 29 alivenessLED = !alivenessLED; /* Do blinky on LED1 while we're waiting for BLE events. This is optional. */
rgrover1 0:332983584a9c 30 }
rgrover1 0:332983584a9c 31
rgrover1 9:69a2ad0bcdb7 32 /*
rgrover1 9:69a2ad0bcdb7 33 * This function is called every time we scan an advertisement.
rgrover1 9:69a2ad0bcdb7 34 */
sunsmile2015 6:850f44146c9f 35 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
sunsmile2015 6:850f44146c9f 36 {
rgrover1 9:69a2ad0bcdb7 37 struct AdvertisingData_t {
rgrover1 9:69a2ad0bcdb7 38 uint8_t length; /* doesn't include itself */
rgrover1 9:69a2ad0bcdb7 39 GapAdvertisingData::DataType_t dataType;
rgrover1 9:69a2ad0bcdb7 40 uint8_t data[0];
rgrover1 9:69a2ad0bcdb7 41 } PACKED;
rgrover1 9:69a2ad0bcdb7 42
rgrover1 9:69a2ad0bcdb7 43 struct ApplicationData_t {
rgrover1 9:69a2ad0bcdb7 44 uint16_t applicationSpecificId; /* An ID used to identify temperature value
rgrover1 9:69a2ad0bcdb7 45 in the manufacture specific AD data field */
hknydn 12:f4b869da449c 46 //TMP_nrf51::TempSensorValue_t tmpSensorValue; /* User defined application data */
rgrover1 9:69a2ad0bcdb7 47 } PACKED;
rgrover1 9:69a2ad0bcdb7 48
hknydn 12:f4b869da449c 49 static const uint16_t MED_KIMLIK = 0xABCD;
rgrover1 9:69a2ad0bcdb7 50
rgrover1 9:69a2ad0bcdb7 51 /* Search for the manufacturer specific data with matching application-ID */
rgrover1 9:69a2ad0bcdb7 52 AdvertisingData_t *pAdvData;
rgrover1 9:69a2ad0bcdb7 53 size_t index = 0;
rgrover1 9:69a2ad0bcdb7 54 while (index < params->advertisingDataLen) {
rgrover1 9:69a2ad0bcdb7 55 pAdvData = (AdvertisingData_t *)&params->advertisingData[index];
rgrover1 9:69a2ad0bcdb7 56 if (pAdvData->dataType == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) {
sunsmile2015 8:649bd171929e 57 ApplicationData_t *pAppData = (ApplicationData_t *)pAdvData->data;
hknydn 12:f4b869da449c 58 if (pAppData->applicationSpecificId == MED_KIMLIK) {
rgrover1 9:69a2ad0bcdb7 59 /* dump information on the console. */
hknydn 12:f4b869da449c 60
hknydn 12:f4b869da449c 61 pc.printf("%02x%02x",0xFA,0xCC);//BASLANGIC BİTLERİ
hknydn 12:f4b869da449c 62 //MAC adresi, RSSI
hknydn 12:f4b869da449c 63 pc.printf("%02x%02x%02x%02x%02x%02x%d",
hknydn 12:f4b869da449c 64 params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],params->rssi);
hknydn 12:f4b869da449c 65 pc.printf("%02x", params->advertisingDataLen);// AdvDATA UZUNLUGU
hknydn 12:f4b869da449c 66 for (unsigned index = 0; index < params->advertisingDataLen; index++) {
hknydn 12:f4b869da449c 67 pc.printf("%02x", params->advertisingData[index]);
hknydn 12:f4b869da449c 68 }
hknydn 12:f4b869da449c 69 pc.printf("%02x\r",0xFF);// BITIS
hknydn 12:f4b869da449c 70
hknydn 12:f4b869da449c 71 //printf("From [%02x %02x %02x], ", params->peerAddr[2], params->peerAddr[1], params->peerAddr[0]);
hknydn 12:f4b869da449c 72 //printf("Temp is %f\r\n", (TMP_nrf51::TempSensorValue_t)pAppData->tmpSensorValue);
sunsmile2015 7:91324daa3bfa 73 break;
sunsmile2015 7:91324daa3bfa 74 }
sunsmile2015 6:850f44146c9f 75 }
rgrover1 9:69a2ad0bcdb7 76 index += (pAdvData->length + 1);
rgrover1 0:332983584a9c 77 }
rgrover1 0:332983584a9c 78 }
rgrover1 0:332983584a9c 79
andresag 11:16f67d5752e1 80 /**
andresag 11:16f67d5752e1 81 * This function is called when the ble initialization process has failed
andresag 11:16f67d5752e1 82 */
andresag 11:16f67d5752e1 83 void onBleInitError(BLE &ble, ble_error_t error)
andresag 11:16f67d5752e1 84 {
andresag 11:16f67d5752e1 85 /* Initialization error handling should go here */
andresag 11:16f67d5752e1 86 }
andresag 11:16f67d5752e1 87
andresag 11:16f67d5752e1 88 /**
andresag 11:16f67d5752e1 89 * Callback triggered when the ble initialization process has finished
andresag 11:16f67d5752e1 90 */
andresag 11:16f67d5752e1 91 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
andresag 11:16f67d5752e1 92 {
andresag 11:16f67d5752e1 93 BLE& ble = params->ble;
andresag 11:16f67d5752e1 94 ble_error_t error = params->error;
andresag 11:16f67d5752e1 95
andresag 11:16f67d5752e1 96 if (error != BLE_ERROR_NONE) {
andresag 11:16f67d5752e1 97 /* In case of error, forward the error handling to onBleInitError */
andresag 11:16f67d5752e1 98 onBleInitError(ble, error);
andresag 11:16f67d5752e1 99 return;
andresag 11:16f67d5752e1 100 }
andresag 11:16f67d5752e1 101
andresag 11:16f67d5752e1 102 /* Ensure that it is the default instance of BLE */
andresag 11:16f67d5752e1 103 if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
andresag 11:16f67d5752e1 104 return;
andresag 11:16f67d5752e1 105 }
andresag 11:16f67d5752e1 106
andresag 11:16f67d5752e1 107 /* Setup and start scanning */
hknydn 12:f4b869da449c 108 ble.gap().setScanParams(1800 /* scan interval */, 100 /* scan window */);
andresag 11:16f67d5752e1 109 ble.gap().startScan(advertisementCallback);
andresag 11:16f67d5752e1 110 }
andresag 11:16f67d5752e1 111
rgrover1 0:332983584a9c 112 int main(void)
rgrover1 0:332983584a9c 113 {
hknydn 12:f4b869da449c 114 pc.baud(9600); //local terminal baud
andresag 11:16f67d5752e1 115 ticker.attach(periodicCallback, 1); /* trigger sensor polling every 2 seconds */
rgrover1 0:332983584a9c 116
hknydn 12:f4b869da449c 117 for(uint8_t say=0; say<5; say++ )
hknydn 12:f4b869da449c 118 {
hknydn 12:f4b869da449c 119 wait(1);
hknydn 12:f4b869da449c 120 pc.printf("wifi_id=AndroidAP|<>|pass=duqy0286");
hknydn 12:f4b869da449c 121 pc.printf("\r");
hknydn 12:f4b869da449c 122
hknydn 12:f4b869da449c 123 }
hknydn 12:f4b869da449c 124
hknydn 12:f4b869da449c 125
andresag 11:16f67d5752e1 126 BLE &ble = BLE::Instance();
andresag 11:16f67d5752e1 127 ble.init(bleInitComplete);
rgrover1 0:332983584a9c 128
rgrover1 0:332983584a9c 129 while (true) {
rgrover1 0:332983584a9c 130 ble.waitForEvent();
rgrover1 0:332983584a9c 131 }
rgrover1 0:332983584a9c 132 }