ESP8266 and nRF51822 simple WiFi connection and temperature publishing to a socket server.
Dependencies: BLE_API DnsQuery ESP8266Interface NetworkSocketAPI mbed nRF51822
Fork of BLE_TemperatureBeacon by
main.cpp
- Committer:
- kixorz
- Date:
- 2015-08-29
- Revision:
- 6:d5f97e422fed
- Parent:
- 5:f4d74a8cad43
File content as of revision 6:d5f97e422fed:
/* mbed Microcontroller Library * Copyright (c) 2006-2015 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "mbed.h" #include "toolchain.h" #include "ble/BLE.h" #include "HealthThermometerService.h" BLE ble; static Ticker ticker; static const uint16_t uuid16_list[] = {GattService::UUID_HEALTH_THERMOMETER_SERVICE}; const static char DEVICE_NAME[] = "Tower Thermometer"; extern float getTemp(); extern void wifiInit(); extern void wifiSend(float temp); void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { ble.gap().startAdvertising(); } int main(void) { //wifi init wifiInit(); //ble advertising /* ble.init(); ble.gap().onDisconnection(disconnectionCallback); HealthThermometerService thermometerService(ble, getTemp(), HealthThermometerService::LOCATION_EAR); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(500); ble.gap().startAdvertising(); */ while (1) { float temp = getTemp(); wifiSend(temp); //thermometerService.updateTemperature( temp ); //ble.waitForEvent(); wait(3); } }