티스토리 뷰
To add manufactererdata
Change manufacturerdata every 2 second
#include <WiFiNINA.h>
#include <time.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <ArduinoBLE.h>
#include "BConstants.h"
#define PIN_Tx0 0
#define PIN_Rx0 1
#define PIN_UARTCONTROL 2
#define PIN_LED 2
#define PIN_IRRx0 3
#define PIN_IRTx0 4
#define PIN_SWITCHIN 5
#define PIN_RELAYCONTROL 6
#define PIN_DRIVER1 7
#define PIN_DRIVER2 8
#define PIN_DRIVER3 9
#define PIN_DRIVER5 10
#define PIN_Rx1 11
#define PIN_Tx1 12
#define PIN_ADC0 A0
#define PIN_ADC1 A1
#define PIN_ADC2 A2
#define NTP_PACKET_SIZE 48
const char WiFi_SSID[] = SECRET_SSID;
const char WiFi_PW[] = SECRET_WIFIPW;
const int TimeZone = 3;
int status = WL_IDLE_STATUS;
byte NTPPacketBuffer[NTP_PACKET_SIZE];
int Count1 = 0;
WiFiClient client;
int ServerStatus = WL_IDLE_STATUS;
WiFiServer server(80);
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214");
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
uint8_t manufacturerData[14] = {0x00, 0xD0, 0x44, 0x65, 0x78, 0x63, 0x6f, 0x6d, 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e};
void setup(){
Serial.begin(9600);
while(!Serial);
pinMode(PIN_LED, OUTPUT);
if(!BLE.begin()){
Serial.print("[?] BLE failed");
while(1);
}
BLE.setLocalName("B-LED");
BLE.setManufacturerData(manufacturerData, sizeof(manufacturerData));
BLE.setConnectable(true);
BLE.setAdvertisedService(ledService);
ledService.addCharacteristic(switchCharacteristic);
BLE.addService(ledService);
switchCharacteristic.writeValue(0);
BLE.advertise();
Serial.println("Started BLE LED Peripheral");
}
void loop(){
BLEDevice central = BLE.central();
if(millis()%2000 == 0){
manufacturerData[3] += 2;
BLE.stopAdvertise();
BLE.setManufacturerData(manufacturerData, sizeof(manufacturerData));
BLE.advertise();
Serial.println(".");
delay(2);
}
if(central){
Serial.print("Connected to central: ");
Serial.println(central.address());
while(central.connected()){
if(switchCharacteristic.written()){
int val = switchCharacteristic.value();
Serial.println(val);
if(val>0){
Serial.println("LED ON");
digitalWrite(PIN_LED, HIGH);
}else{
Serial.println("LED OFF");
digitalWrite(PIN_LED, LOW);
}
}
}
Serial.print(F("Disconnected from central : "));
Serial.println(central.address());
}
}
반응형
'SWDesk > Firmware' 카테고리의 다른 글
[Nano 33 IoT] WiFi Client Example(2) (0) | 2021.11.13 |
---|---|
[Nano 33 IoT] WiFi Client Example(1) (0) | 2021.11.12 |
[Nano 33 IoT] BLE Central Example(1) (0) | 2021.11.09 |
[Nano 33 IoT] BLE Peripheral Example(1) (0) | 2021.11.07 |
[Nano 33 IoT] Configuration (0) | 2021.11.06 |
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 티스토리챌린지
- 혁신
- 허들
- bilient
- Innovations&Hurdles
- 심심풀이
- 전류
- 아두이노
- 둎
- 빌리언트
- Video
- 치매방지
- Innovations
- 전압전류모니터링
- 치매
- Hurdles
- image
- BSC
- 심심풀이치매방지기
- Decorator
- 오블완
- 배프
- Innovation&Hurdles
- 전압
- badp
- 절연형
- DYOV
- arduino
- 혁신과허들
- ServantClock
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함