Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 * Copyright (c) 2016 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * 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, WITHOUT 00012 * 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 #include "mbed.h" 00017 #include "rtos.h" 00018 #include "NanostackInterface.h" 00019 #include "mbed-trace/mbed_trace.h" 00020 #include "mesh_nvm.h" 00021 00022 00023 void trace_printer(const char* str) { 00024 printf("%s\n", str); 00025 } 00026 00027 MeshInterface *mesh; 00028 00029 static Mutex SerialOutMutex; 00030 00031 void thread_eui64_trace() 00032 { 00033 uint8_t eui64[8] = {0}; 00034 static_cast<ThreadInterface*>(mesh)->device_eui64_get(eui64); 00035 printf("Device EUI64 address = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", eui64[0], eui64[1], eui64[2], eui64[3], eui64[4], eui64[5], eui64[6], eui64[7]); 00036 } 00037 00038 void serial_out_mutex_wait() 00039 { 00040 SerialOutMutex.lock(); 00041 } 00042 00043 void serial_out_mutex_release() 00044 { 00045 SerialOutMutex.unlock(); 00046 } 00047 00048 int main() 00049 { 00050 mbed_trace_init(); 00051 mbed_trace_print_function_set(trace_printer); 00052 mbed_trace_mutex_wait_function_set( serial_out_mutex_wait ); 00053 mbed_trace_mutex_release_function_set( serial_out_mutex_release ); 00054 00055 printf("Start mesh-minimal application\n"); 00056 00057 #define STR(s) #s 00058 printf("Build: %s %s\nMesh type: %s\n", __DATE__, __TIME__, STR(MBED_CONF_NSAPI_DEFAULT_MESH_TYPE)); 00059 #ifdef MBED_MAJOR_VERSION 00060 printf("Mbed OS version: %d.%d.%d\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); 00061 #endif 00062 00063 mesh = MeshInterface::get_default_instance(); 00064 if (!mesh) { 00065 printf("Error! MeshInterface not found!\n"); 00066 return -1; 00067 } 00068 00069 thread_eui64_trace(); 00070 mesh_nvm_initialize(); 00071 printf("Connecting...\n"); 00072 int error = mesh->connect(); 00073 if (error) { 00074 printf("Connection failed! %d\n", error); 00075 return error; 00076 } 00077 00078 while (NULL == mesh->get_ip_address()) 00079 ThisThread::sleep_for(500); 00080 00081 printf("Connected. IP = %s\n", mesh->get_ip_address()); 00082 }
Generated on Wed Jul 13 2022 19:59:28 by
1.7.2