sdasd

Dependencies:   BLE_API mbed nRF51822

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

Committer:
hknydn
Date:
Thu Jun 30 07:09:50 2016 +0000
Revision:
14:59ba4a2a17c7
Parent:
13:5f87b9cdeb6f
Child:
15:a88e0135e67e
A

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 #include "mbed.h"
rgrover1 9:69a2ad0bcdb7 17 #include "toolchain.h"
rgrover1 9:69a2ad0bcdb7 18 #include "ble/BLE.h"
hknydn 12:f4b869da449c 19
hknydn 13:5f87b9cdeb6f 20 //ABCD bir kimlik olarak belirlenir ve şifre vazifedi görür herhangi bir bluetooth modülü ABCD içerirse burada görülecektir.
hknydn 13:5f87b9cdeb6f 21 //Yayın okuyan program
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 /* Search for the manufacturer specific data with matching application-ID */
rgrover1 9:69a2ad0bcdb7 51 AdvertisingData_t *pAdvData;
rgrover1 9:69a2ad0bcdb7 52 size_t index = 0;
rgrover1 9:69a2ad0bcdb7 53 while (index < params->advertisingDataLen) {
rgrover1 9:69a2ad0bcdb7 54 pAdvData = (AdvertisingData_t *)&params->advertisingData[index];
rgrover1 9:69a2ad0bcdb7 55 if (pAdvData->dataType == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) {
sunsmile2015 8:649bd171929e 56 ApplicationData_t *pAppData = (ApplicationData_t *)pAdvData->data;
hknydn 13:5f87b9cdeb6f 57 if (pAppData->applicationSpecificId == MED_KIMLIK ) {
rgrover1 9:69a2ad0bcdb7 58 /* dump information on the console. */
hknydn 14:59ba4a2a17c7 59 pc.printf("name=aysegul&pass=123&sender=sniffer1&temparaturedata=");// Birinci Sniffer
hknydn 12:f4b869da449c 60 pc.printf("%02x%02x",0xFA,0xCC);//BASLANGIC BİTLERİ
hknydn 12:f4b869da449c 61 //MAC adresi, RSSI
hknydn 13:5f87b9cdeb6f 62 pc.printf("%02x%02x%02x%02x%02x%02x%x",
hknydn 13:5f87b9cdeb6f 63 params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],((params->rssi)*-1));
hknydn 12:f4b869da449c 64 pc.printf("%02x", params->advertisingDataLen);// AdvDATA UZUNLUGU
hknydn 13:5f87b9cdeb6f 65 /* RSSI DEĞERİNİ DECİMALE ÇEVİRDİKTEN SONRA -1 İLE ÇARPILMALIDIR. */
hknydn 13:5f87b9cdeb6f 66 for (unsigned index = 0; index < params->advertisingDataLen; index++)
hknydn 13:5f87b9cdeb6f 67 {
hknydn 14:59ba4a2a17c7 68 pc.printf("%02x", params->advertisingData[index]);
hknydn 12:f4b869da449c 69 }
hknydn 13:5f87b9cdeb6f 70 pc.printf("%02x\r",0xFF);// BITIS
hknydn 14:59ba4a2a17c7 71
sunsmile2015 7:91324daa3bfa 72 break;
sunsmile2015 7:91324daa3bfa 73 }
sunsmile2015 6:850f44146c9f 74 }
rgrover1 9:69a2ad0bcdb7 75 index += (pAdvData->length + 1);
rgrover1 0:332983584a9c 76 }
rgrover1 0:332983584a9c 77 }
rgrover1 0:332983584a9c 78
andresag 11:16f67d5752e1 79 /**
andresag 11:16f67d5752e1 80 * This function is called when the ble initialization process has failed
andresag 11:16f67d5752e1 81 */
andresag 11:16f67d5752e1 82 void onBleInitError(BLE &ble, ble_error_t error)
andresag 11:16f67d5752e1 83 {
andresag 11:16f67d5752e1 84 /* Initialization error handling should go here */
andresag 11:16f67d5752e1 85 }
andresag 11:16f67d5752e1 86
andresag 11:16f67d5752e1 87 /**
andresag 11:16f67d5752e1 88 * Callback triggered when the ble initialization process has finished
andresag 11:16f67d5752e1 89 */
andresag 11:16f67d5752e1 90 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
andresag 11:16f67d5752e1 91 {
andresag 11:16f67d5752e1 92 BLE& ble = params->ble;
andresag 11:16f67d5752e1 93 ble_error_t error = params->error;
andresag 11:16f67d5752e1 94
andresag 11:16f67d5752e1 95 if (error != BLE_ERROR_NONE) {
andresag 11:16f67d5752e1 96 /* In case of error, forward the error handling to onBleInitError */
andresag 11:16f67d5752e1 97 onBleInitError(ble, error);
andresag 11:16f67d5752e1 98 return;
andresag 11:16f67d5752e1 99 }
andresag 11:16f67d5752e1 100
andresag 11:16f67d5752e1 101 /* Ensure that it is the default instance of BLE */
andresag 11:16f67d5752e1 102 if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
andresag 11:16f67d5752e1 103 return;
andresag 11:16f67d5752e1 104 }
andresag 11:16f67d5752e1 105
andresag 11:16f67d5752e1 106 /* Setup and start scanning */
hknydn 12:f4b869da449c 107 ble.gap().setScanParams(1800 /* scan interval */, 100 /* scan window */);
andresag 11:16f67d5752e1 108 ble.gap().startScan(advertisementCallback);
andresag 11:16f67d5752e1 109 }
andresag 11:16f67d5752e1 110
rgrover1 0:332983584a9c 111 int main(void)
rgrover1 0:332983584a9c 112 {
hknydn 12:f4b869da449c 113 pc.baud(9600); //local terminal baud
andresag 11:16f67d5752e1 114 ticker.attach(periodicCallback, 1); /* trigger sensor polling every 2 seconds */
rgrover1 0:332983584a9c 115
hknydn 12:f4b869da449c 116 for(uint8_t say=0; say<5; say++ )
hknydn 12:f4b869da449c 117 {
hknydn 12:f4b869da449c 118 wait(1);
hknydn 13:5f87b9cdeb6f 119 pc.printf("wifi_id=MedronTeknoloji|<>|pass=medron2011");
hknydn 13:5f87b9cdeb6f 120
hknydn 13:5f87b9cdeb6f 121 //pc.printf("wifi_id=AndroidAP|<>|pass=duqy0286"); //Ayşegülün telefonuna bağlanırken kullanıyorduk
hknydn 12:f4b869da449c 122 pc.printf("\r");
hknydn 12:f4b869da449c 123
hknydn 12:f4b869da449c 124 }
hknydn 12:f4b869da449c 125
hknydn 12:f4b869da449c 126
andresag 11:16f67d5752e1 127 BLE &ble = BLE::Instance();
andresag 11:16f67d5752e1 128 ble.init(bleInitComplete);
rgrover1 0:332983584a9c 129
rgrover1 0:332983584a9c 130 while (true) {
rgrover1 0:332983584a9c 131 ble.waitForEvent();
rgrover1 0:332983584a9c 132 }
rgrover1 0:332983584a9c 133 }