Using BLE to control WIFI configuration as SSID and PW.
Dependencies: BLE_API WIFI_API_32kRAM mbed nRF51822
Fork of NNN40_WiFi by
BLE_WIFIControl enables user to setup Wifi connection via BLE link. Here is iPhone app that teaches you how to use this BLE_WIFIControl example. /media/uploads/Marcomissyou/ios_app_for_wifi_configure.pdf
Diff: main.cpp
- Revision:
- 7:5d82c92ec2a3
- Parent:
- 3:65c5fce3a471
- Child:
- 8:d39bc94f139b
--- a/main.cpp Tue Mar 31 08:20:24 2015 +0000
+++ b/main.cpp Mon May 18 07:13:04 2015 +0000
@@ -1,32 +1,70 @@
#include "mbed.h"
+#include "BLEDevice.h"
+#include "BLEControlWIFIService.h"
+#include "DeviceInformationService.h"
#include "WIFIDevice.h"
#include "EthernetInterface.h"
+
+#define UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL 0
+
+BLEDevice ble;
WIFIDevice wifi;
+EthernetInterface eth;
+
+Ticker tickerSensorPolling;
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut RFSWIO(p19);
+
+const static char DEVICE_NAME[] = "BLE WCS";
+static volatile bool triggerSensorPolling = false;
+
+void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
+{
+ ble.startAdvertising(); // restart advertising
+}
const char* PC_SERVER_ADDRESS = "192.168.1.234";
uint16_t PC_PORT = 5222;
-DigitalOut LED01(LED1);
-DigitalOut LED02(LED2);
-
+
int main(void)
-{
- EthernetInterface eth;
+{
eth.init(); //Use DHCP
- wait(1);
- // set given SSID and PW as the highest priority
- wifi.setNetwork("HTCSV", "11111111", 0);
- wait(1);
- LED01 = 1;
- eth.connect(40000);
-
- LED02 = 1;
- TCPSocketConnection socket;
- socket.connect(PC_SERVER_ADDRESS,PC_PORT);
- char msg[] = "Hello World";
- socket.send(msg, sizeof(msg));
-
- socket.close();
- eth.disconnect();
- wifi.sleep();
-}
+ RFSWIO = 0;
+ ble.init();
+ ble.onDisconnection(disconnectionCallback);
+
+ /* Setup primary service. */
+ BLEControlWIFIService BLEWIFIService(ble, wifi);
+
+ /* Setup auxiliary service. */
+ DeviceInformationService deviceInfo(ble, "ARM", "Cyntec", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
+
+ /* Setup advertising. */
+ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+ ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)UUID_WIFI_CONFIGURATION_SERVICE, sizeof(UUID_WIFI_CONFIGURATION_SERVICE));
+ ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+ ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+ ble.setAdvertisingInterval(1000);
+ ble.startAdvertising();
+
+ // infinite loop
+ while (1) {
+ if (ble.getGapState().connected && BLEWIFIService.is_config) {
+ BLEWIFIService.is_config = false;
+ eth.connect(40000);
+ TCPSocketConnection sock;
+ sock.connect(PC_SERVER_ADDRESS,PC_PORT);
+ led1 = 1;
+ if(sock.is_connected()){
+ led2 = 1;
+ char msg[] = "Hello World";
+ sock.send(msg, sizeof(msg));
+ }
+
+ } else {
+ ble.waitForEvent(); // low power wait for event
+ }
+ }
+}
\ No newline at end of file
