Example of AWS IoT connection and Web Dashboard thru STM32 Nucleo evaluation board and mbed OS.

Dependencies:   X_NUCLEO_IKS01A1 mbed FP MQTTPacket DnsQuery ATParser

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NetworkStack.cpp Source File

NetworkStack.cpp

00001 /* Socket
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 "DnsQuery.h"
00018 #include "mbed.h"
00019 
00020 int NetworkStack::gethostbyname(SocketAddress *address, const char *name)
00021 {
00022     char buffer[NSAPI_IP_SIZE];
00023     UDPSocket sock(this);
00024 
00025     sock.set_timeout(3000);
00026 
00027     int err = dnsQuery(&sock, name, buffer);
00028     
00029     if (err) 
00030     {
00031         return err;
00032     }
00033 
00034     address->set_ip_address(buffer);
00035     return 0;
00036 }
00037 
00038 int NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen)
00039 {
00040     return NSAPI_ERROR_UNSUPPORTED;
00041 }
00042 
00043 int NetworkStack::getstackopt(int level, int optname, void *optval, unsigned *optlen)
00044 {
00045     return NSAPI_ERROR_UNSUPPORTED;
00046 }
00047 
00048 int NetworkStack::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen)
00049 {
00050     return NSAPI_ERROR_UNSUPPORTED;
00051 }
00052 
00053 int NetworkStack::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen)
00054 {
00055     return NSAPI_ERROR_UNSUPPORTED;
00056 }