989
Dependencies: mbed Servo X_NUCLEO_IKS01A2 X_NUCLEO_IDW01M1v2 NetworkSocketAPI NDefLib MQTT
main.cpp@2:ba0531d896f0, 2016-04-13 (annotated)
- Committer:
- mridup
- Date:
- Wed Apr 13 10:14:35 2016 +0000
- Revision:
- 2:ba0531d896f0
- Parent:
- 1:041e9f05738c
- Child:
- 3:dfb8c6c8c31b
file-name changes. wifi-wakeup() delay. Socket.recv() returns bytes_read on time_out, even if bytes_read is 0.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mridup | 2:ba0531d896f0 | 1 | /* NetworkSocketAPI Example Program |
mridup | 2:ba0531d896f0 | 2 | * Copyright (c) 2015 ARM Limited |
mridup | 2:ba0531d896f0 | 3 | * |
mridup | 2:ba0531d896f0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mridup | 2:ba0531d896f0 | 5 | * you may not use this file except in compliance with the License. |
mridup | 2:ba0531d896f0 | 6 | * You may obtain a copy of the License at |
mridup | 2:ba0531d896f0 | 7 | * |
mridup | 2:ba0531d896f0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mridup | 2:ba0531d896f0 | 9 | * |
mridup | 2:ba0531d896f0 | 10 | * Unless required by applicable law or agreed to in writing, software |
mridup | 2:ba0531d896f0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mridup | 2:ba0531d896f0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mridup | 2:ba0531d896f0 | 13 | * See the License for the specific language governing permissions and |
mridup | 2:ba0531d896f0 | 14 | * limitations under the License. |
mridup | 2:ba0531d896f0 | 15 | */ |
mridup | 2:ba0531d896f0 | 16 | |
mridup | 0:cbf8bc43bc9e | 17 | #include "mbed.h" |
mridup | 0:cbf8bc43bc9e | 18 | #include "SPWFInterface.h" |
mridup | 2:ba0531d896f0 | 19 | #include "NSAPITests.h" |
mridup | 0:cbf8bc43bc9e | 20 | |
mridup | 0:cbf8bc43bc9e | 21 | //------------------------------------ |
mridup | 0:cbf8bc43bc9e | 22 | // Hyperterminal configuration |
mridup | 0:cbf8bc43bc9e | 23 | // 9600 bauds, 8-bit data, no parity |
mridup | 0:cbf8bc43bc9e | 24 | //------------------------------------ |
mridup | 0:cbf8bc43bc9e | 25 | |
mridup | 0:cbf8bc43bc9e | 26 | Serial pc(SERIAL_TX, SERIAL_RX); |
mridup | 0:cbf8bc43bc9e | 27 | |
mridup | 0:cbf8bc43bc9e | 28 | SpwfSAInterface *spwf; |
mridup | 2:ba0531d896f0 | 29 | |
mridup | 2:ba0531d896f0 | 30 | int main() |
mridup | 2:ba0531d896f0 | 31 | { |
mridup | 2:ba0531d896f0 | 32 | int32_t err; |
mridup | 0:cbf8bc43bc9e | 33 | char * ssid = "STM"; |
mridup | 0:cbf8bc43bc9e | 34 | char * seckey = "STMdemoPWD"; |
mridup | 2:ba0531d896f0 | 35 | |
mridup | 0:cbf8bc43bc9e | 36 | spwf = createSPWFInstance(); |
mridup | 0:cbf8bc43bc9e | 37 | err = spwf->init(); |
mridup | 0:cbf8bc43bc9e | 38 | if(err!=0) |
mridup | 0:cbf8bc43bc9e | 39 | { |
mridup | 2:ba0531d896f0 | 40 | pc.printf("\r\nerror initializing.\r\n"); |
mridup | 0:cbf8bc43bc9e | 41 | return -1; |
mridup | 0:cbf8bc43bc9e | 42 | } |
mridup | 0:cbf8bc43bc9e | 43 | |
mridup | 2:ba0531d896f0 | 44 | pc.printf("\r\nconnecting to AP\r\n"); |
mridup | 0:cbf8bc43bc9e | 45 | |
mridup | 2:ba0531d896f0 | 46 | err = spwf->connect(ssid, seckey, NS_SECURITY_WPA); |
mridup | 2:ba0531d896f0 | 47 | |
mridup | 2:ba0531d896f0 | 48 | if (err) { |
mridup | 2:ba0531d896f0 | 49 | printf("Interface failed to connect with code %d\r\n", err); |
mridup | 2:ba0531d896f0 | 50 | } else { |
mridup | 2:ba0531d896f0 | 51 | nsapi_tests("SPWF Tests", spwf, "192.168.1.5", 32001); |
mridup | 2:ba0531d896f0 | 52 | spwf->disconnect(); |
mridup | 0:cbf8bc43bc9e | 53 | } |
mridup | 2:ba0531d896f0 | 54 | while(1); |
mridup | 2:ba0531d896f0 | 55 | } |