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 Bluetooth Low Energy

Committer:
kixorz
Date:
Sat Aug 29 21:58:02 2015 +0000
Revision:
6:d5f97e422fed
Parent:
5:f4d74a8cad43
wifi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sunsmile2015 0:3dc6e424dba0 1 /* mbed Microcontroller Library
sunsmile2015 0:3dc6e424dba0 2 * Copyright (c) 2006-2015 ARM Limited
sunsmile2015 0:3dc6e424dba0 3 *
sunsmile2015 0:3dc6e424dba0 4 * Licensed under the Apache License, Version 2.0 (the "License");
sunsmile2015 0:3dc6e424dba0 5 * you may not use this file except in compliance with the License.
sunsmile2015 0:3dc6e424dba0 6 * You may obtain a copy of the License at
sunsmile2015 0:3dc6e424dba0 7 *
sunsmile2015 0:3dc6e424dba0 8 * http://www.apache.org/licenses/LICENSE-2.0
sunsmile2015 0:3dc6e424dba0 9 *
sunsmile2015 0:3dc6e424dba0 10 * Unless required by applicable law or agreed to in writing, software
sunsmile2015 0:3dc6e424dba0 11 * distributed under the License is distributed on an "AS IS" BASIS,
sunsmile2015 0:3dc6e424dba0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sunsmile2015 0:3dc6e424dba0 13 * See the License for the specific language governing permissions and
sunsmile2015 0:3dc6e424dba0 14 * limitations under the License.
sunsmile2015 0:3dc6e424dba0 15 */
sunsmile2015 0:3dc6e424dba0 16
sunsmile2015 0:3dc6e424dba0 17 #include "mbed.h"
rgrover1 5:f4d74a8cad43 18 #include "toolchain.h"
sunsmile2015 0:3dc6e424dba0 19 #include "ble/BLE.h"
kixorz 6:d5f97e422fed 20 #include "HealthThermometerService.h"
sunsmile2015 0:3dc6e424dba0 21
rgrover1 5:f4d74a8cad43 22 BLE ble;
sunsmile2015 3:3eda308b78e6 23
rgrover1 5:f4d74a8cad43 24 static Ticker ticker;
kixorz 6:d5f97e422fed 25 static const uint16_t uuid16_list[] = {GattService::UUID_HEALTH_THERMOMETER_SERVICE};
kixorz 6:d5f97e422fed 26 const static char DEVICE_NAME[] = "Tower Thermometer";
sunsmile2015 0:3dc6e424dba0 27
kixorz 6:d5f97e422fed 28 extern float getTemp();
sunsmile2015 4:e5fa4c8838db 29
kixorz 6:d5f97e422fed 30 extern void wifiInit();
kixorz 6:d5f97e422fed 31 extern void wifiSend(float temp);
sunsmile2015 0:3dc6e424dba0 32
kixorz 6:d5f97e422fed 33 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
sunsmile2015 2:b935358da5ba 34 {
sunsmile2015 4:e5fa4c8838db 35 ble.gap().startAdvertising();
sunsmile2015 4:e5fa4c8838db 36 }
sunsmile2015 4:e5fa4c8838db 37
sunsmile2015 2:b935358da5ba 38 int main(void)
kixorz 6:d5f97e422fed 39 {
kixorz 6:d5f97e422fed 40 //wifi init
kixorz 6:d5f97e422fed 41 wifiInit();
kixorz 6:d5f97e422fed 42
kixorz 6:d5f97e422fed 43 //ble advertising
kixorz 6:d5f97e422fed 44 /*
sunsmile2015 0:3dc6e424dba0 45 ble.init();
kixorz 6:d5f97e422fed 46 ble.gap().onDisconnection(disconnectionCallback);
kixorz 6:d5f97e422fed 47 HealthThermometerService thermometerService(ble, getTemp(), HealthThermometerService::LOCATION_EAR);
kixorz 6:d5f97e422fed 48
kixorz 6:d5f97e422fed 49 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
kixorz 6:d5f97e422fed 50 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
kixorz 6:d5f97e422fed 51 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER);
kixorz 6:d5f97e422fed 52 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
kixorz 6:d5f97e422fed 53 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
kixorz 6:d5f97e422fed 54 ble.gap().setAdvertisingInterval(500);
kixorz 6:d5f97e422fed 55 ble.gap().startAdvertising();
kixorz 6:d5f97e422fed 56 */
kixorz 6:d5f97e422fed 57 while (1) {
kixorz 6:d5f97e422fed 58 float temp = getTemp();
rgrover1 5:f4d74a8cad43 59
kixorz 6:d5f97e422fed 60 wifiSend(temp);
kixorz 6:d5f97e422fed 61 //thermometerService.updateTemperature( temp );
rgrover1 5:f4d74a8cad43 62
kixorz 6:d5f97e422fed 63 //ble.waitForEvent();
kixorz 6:d5f97e422fed 64 wait(3);
sunsmile2015 0:3dc6e424dba0 65 }
sunsmile2015 0:3dc6e424dba0 66 }