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
main.cpp
- Committer:
- wgd8700
- Date:
- 2015-08-14
- Revision:
- 9:16ac259b2ce7
- Parent:
- 8:d39bc94f139b
- Child:
- 10:5cffa136892c
File content as of revision 9:16ac259b2ce7:
#include "mbed.h"
#include "BLE.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);
bool is_AP_connect = false;
const static char DEVICE_NAME[] = "TSUNGTA_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.15.101";
uint16_t PC_PORT = 5222;
int main(void)
{
//NRF_CLOCK->XTALFREQ = 0x00; //Tsungta, Used to active radio correctly external when XTAL 32MHz is loaded
TCPSocketConnection sock;
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;
//ble.shutdown();
eth.init(); //Use DHCP
RFSWIO = 1; //Switch RF to WiFi
while (eth.connect()) {}
is_AP_connect = true;
} else {
if (is_AP_connect) {
if(!sock.is_connected()){
sock.connect(PC_SERVER_ADDRESS,PC_PORT);
led1 = 1;
} else {
char msg[] = "Hello World";
sock.send(msg, sizeof(msg));
wait(1);
}
}
ble.waitForEvent(); // low power wait for event
}
}
}
