Adam Konrad / Mbed 2 deprecated TempTower

Dependencies:   BLE_API DnsQuery ESP8266Interface NetworkSocketAPI mbed nRF51822

Fork of BLE_TemperatureBeacon by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wifi.cpp Source File

wifi.cpp

00001 /* NetworkSocketAPI Example Program
00002  * Copyright (c) 2015 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "mbed.h"
00018 #include "ESP8266Interface.h"
00019 
00020 DigitalOut myled(LED1);
00021 DigitalOut status(LED2);
00022 void flash(){ myled = !myled; }
00023 
00024 void setStatus(int num){
00025     for(int i = 0; i < num * 2; ++i){
00026         status = !status;
00027         wait(0.2f);
00028     }
00029 }
00030 
00031 ESP8266Interface wifi(P0_23, P0_21);
00032 
00033 static SocketInterface* mySocket;
00034 void wifiInit() {
00035     wifi.init();
00036     int cs = wifi.connect("DemoRoom", "");
00037     setStatus(cs == 0 ? 1 : 3);
00038 
00039     mySocket = wifi.allocateSocket(SOCK_TCP);
00040 
00041     mySocket->setAddressPort("192.168.2.235", 1234);
00042     mySocket->open();
00043     
00044     //TODO
00045     //mySocket->close();
00046     //wifi.disconnect();
00047 }
00048 
00049 void wifiSend(float temp) {
00050     setStatus(1);
00051     mySocket->send(&temp, sizeof(temp), 100);
00052 }