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.
Dependencies: EthernetInterface FluentLogger mbed-rtos mbed
main.cpp
00001 /* FluentLogger - fluent-logger-mbed sample 00002 * Copyright (c) 2014 Yuuichi Akagawa 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 "EthernetInterface.h" 00019 #include "FluentLogger.h" 00020 00021 EthernetInterface eth; 00022 FluentLogger logger("192.168.0.1"); // please set your Fluentd server 00023 00024 int main() 00025 { 00026 eth.init(); //Use DHCP 00027 eth.connect(); 00028 uMP mp(64); //Message body 00029 00030 logger.open(); //connect to fluentd server (omissible) 00031 00032 //sample 00033 //array sample with primitive functions 00034 //YYYY-MM-DD HH:MM:SS zzzzz debug.test: ["sint",0,1,-1,-128,-32768,-2147483648] 00035 mp.init(); // need init every time 00036 mp.start_array(7); // declare array for seven elements. it can mixed type. 00037 mp.set_str("sint", 4); // 1st element 00038 mp.set_sint(0); // 2nd element 00039 mp.set_sint(1); // 3rd element 00040 mp.set_sint(-1); // 4th element 00041 mp.set_sint(-128); // 5th element 00042 mp.set_sint(-32768); // 6th element 00043 mp.set_sint(-2147483648); // 7th element 00044 logger.log("debug.test", mp); // emit 00045 00046 //array sample with primitive functions 00047 //YYYY-MM-DD HH:MM:SS zzzzz debug.test: ["uint",0,1,128,255,65535,4294967295] 00048 mp.init(); // need init every time 00049 mp.start_array(7); // declare array for seven elements. it can mixed type. 00050 mp.set_str("uint", 4); // 1st element 00051 mp.set_uint(0); // 2nd element 00052 mp.set_uint(1); // 3rd element 00053 mp.set_uint(128); // 4th element 00054 mp.set_uint(0xff); // 5th element 00055 mp.set_uint(0xffff); // 6th element 00056 mp.set_uint(0xffffffff); // 7th element 00057 logger.log("debug.test", mp); 00058 00059 //map sample with primitive functions 00060 //YYYY-MM-DD HH:MM:SS zzzzz debug.test: {"string":"Hi!","float":0.3333333432674408,"double":0.3333333333333333} 00061 mp.init(); // need init every time 00062 mp.start_map(3); // declare map for three paires. 00063 mp.set_str("string", 6); // 1st key 00064 mp.set_str("Hi!", 3); // 1st value 00065 mp.set_str("float", 5); // 2nd key 00066 mp.set_float(1.0/3); // 2nd value 00067 mp.set_str("double", 6); // 3rd key 00068 mp.set_double(1.0/3); // 3rd value 00069 logger.log("debug.test", mp); // emit 00070 00071 //map sample with simple method. same as prev sample (but need more CPU cycle) 00072 //YYYY-MM-DD HH:MM:SS zzzzz debug.test: {"string":"Hi!","float":0.3333333432674408,"double":0.3333333333333333} 00073 mp.init(); // need init every time 00074 mp.start_map(3); // declare map for two paires. 00075 mp.map("string", "Hi!"); // 1st key/value pair 00076 mp.map("float", (float)(1.0/3)); // 2nd key/value pair 00077 mp.map("double", (double)(1.0/3)); // 3rd key/value pair 00078 logger.log("debug.mbed", mp); // emit 00079 00080 while(1) { 00081 logger.log("debug.mbed", "Hello mbed"); //message body is simple string 00082 logger.close(); //close a connection (if you want) 00083 wait_ms(10000); 00084 } 00085 eth.disconnect(); 00086 }
Generated on Wed Jul 20 2022 19:21:41 by
1.7.2