本文整理汇总了C++中EthernetInterface::getIPAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ EthernetInterface::getIPAddress方法的具体用法?C++ EthernetInterface::getIPAddress怎么用?C++ EthernetInterface::getIPAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EthernetInterface
的用法示例。
在下文中一共展示了EthernetInterface::getIPAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (void) {
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(udpecho_server_auto);
MBED_HOSTTEST_DESCRIPTION(UDP echo server);
MBED_HOSTTEST_START("NET_5");
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("MBED: Server IP Address is %s:%d\r\n", eth.getIPAddress(), ECHO_SERVER_PORT);
UDPSocket server;
server.bind(ECHO_SERVER_PORT);
Endpoint client;
char buffer[BUFFER_SIZE] = {0};
printf("MBED: Waiting for packet...\r\n");
while (true) {
int n = server.receiveFrom(client, buffer, sizeof(buffer));
if (n > 0) {
//printf("Received packet from: %s\n", client.get_address());
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE-1 : n;
buffer[buffer_string_end_index] = '\0';
//printf("Server received: %s\n", buffer);
server.sendTo(client, buffer, n);
}
}
}
示例2: app_start
void app_start(int argc, char *argv[]) {
(void)argc;
(void)argv;
MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(tcpecho_client_auto);
MBED_HOSTTEST_DESCRIPTION(TCP echo client);
MBED_HOSTTEST_START("NET_4");
socket_error_t err = lwipv4_socket_init();
TEST_EQ(err, SOCKET_ERROR_NONE);
memset(buffer, 0, sizeof(buffer));
port = 0;
s_ip_address ip_addr = {0, 0, 0, 0};
printf("TCPClient waiting for server IP and port..." NL);
scanf("%d.%d.%d.%d:%d", &ip_addr.ip_1, &ip_addr.ip_2, &ip_addr.ip_3, &ip_addr.ip_4, &port);
printf("Address received:%d.%d.%d.%d:%d" NL, ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4, port);
eth.init(); //Use DHCP
eth.connect();
printf("TCPClient IP Address is %s" NL, eth.getIPAddress());
sprintf(buffer, "%d.%d.%d.%d", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4);
client = new TCPEchoClient(SOCKET_STACK_LWIP_IPV4);
{
FunctionPointer2<void, char *, uint16_t> fp(client, &TCPEchoClient::start_test);
minar::Scheduler::postCallback(fp.bind(buffer, port));
}
}
示例3: main
int main() {
printf("{{start}}\r\n");
EthernetInterface eth;
/* Initialise with DHCP, connect, and start up the stack */
eth.init();
eth.connect();
lwipv4_socket_init();
printf("UDP client IP Address is %s\r\n", eth.getIPAddress());
/* Get the current time */
UDPGetTime gt;
{
FunctionPointer1<void, const char*> fp(>, &UDPGetTime::startGetTime);
minar::Scheduler::postCallback(fp.bind(HTTP_SERVER_NAME));
}
minar::Scheduler::start();
printf("UDP: %lu seconds since 01/01/1900 00:00 GMT\r\n", gt.time());
eth.disconnect();
float years = (float) gt.time() / 60 / 60 / 24 / 365;
printf("{{%s}}\r\n",(years < YEARS_TO_PASS ?"failure":"success"));
printf("{{end}}\r\n");
return 0;
}
示例4: app_start
void app_start(int /*argc*/, char* /*argv*/[]) {
//Sets the console baud-rate
output.baud(115200);
// MAC address handling
mbed_mac_address(mmac);
// This sets up the network interface configuration which will be used
// by LWM2M Client API to communicate with mbed Device server.
//eth.init("192.168.1.248","255.255.255.0","192.168.1.1");
eth.init(); //Use DHCP
eth.connect();
lwipv4_socket_init();
output.printf("IP address %s\r\n", eth.getIPAddress());
// On press of SW3 button on K64F board, example application
// will call unregister API towards mbed Device Server
unreg_button.fall(&mbed_client,&MbedClient::test_unregister);
// On press of SW2 button on K64F board, example application
// will send observation towards mbed Device Server
obs_button.fall(&mbed_client,&MbedClient::update_resource);
// Create LWM2M Client API interface to manage register and unregister
mbed_client.create_interface();
// Create LWM2M server object specifying mbed device server
// information.
M2MSecurity* register_object = mbed_client.create_register_object();
// Create LWM2M device object specifying device resources
// as per OMA LWM2M specification.
M2MDevice* device_object = mbed_client.create_device_object();
// Create Generic object specifying custom resources
M2MObject* generic_object = mbed_client.create_generic_object();
// Create LED Object
M2MObject* led_object = mbed_client.create_led_object();
// Add all the objects that you would like to register
// into the list and pass the list for register API.
M2MObjectList object_list;
object_list.push_back(device_object);
object_list.push_back(generic_object);
object_list.push_back(led_object);
mbed_client.set_register_object(register_object);
// Issue register command.
FunctionPointer2<void, M2MSecurity*, M2MObjectList> fp(&mbed_client, &MbedClient::test_register);
minar::Scheduler::postCallback(fp.bind(register_object,object_list));
minar::Scheduler::postCallback(&mbed_client,&MbedClient::test_update_register).period(minar::milliseconds(25000));
}
示例5: setupEthernet
void setupEthernet()
{
lcd.printf("Setup Ethernet...\r\n"); // Starting
eth.init(); // Initialize
while (eth.connect()) { // timeout and loop until connected
lcd.printf("Connect timeout\r\n");
};
lcd.printf("IP Address is %s\r\n", eth.getIPAddress()); // successful connect
}
示例6: app_start
void app_start(int argc, char *argv[]) {
(void) argc;
(void) argv;
eth.init(); //Use DHCP
eth.connect();
lwipv4_socket_init();
printf("MBED: Server IP Address is %s:%d\r\n", eth.getIPAddress(), ECHO_SERVER_PORT);
mbed::FunctionPointer1<void, uint16_t> fp(&server, &TCPEchoServer::start);
minar::Scheduler::postCallback(fp.bind(ECHO_SERVER_PORT));
}
示例7: ethSetup
void ethSetup()
{
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
udp.init();
udp.bind(5683);
udp.set_blocking(false, 10000);
}
示例8: main
int main() {
char buffer[BUFFER_SIZE] = {0};
char out_buffer[BUFFER_SIZE] = {0};
s_ip_address ip_addr = {0, 0, 0, 0};
int port = 0;
printf("MBED: TCPCllient waiting for server IP and port...\r\n");
scanf("%d.%d.%d.%d:%d", &ip_addr.ip_1, &ip_addr.ip_2, &ip_addr.ip_3, &ip_addr.ip_4, &port);
printf("MBED: Address received: %d.%d.%d.%d:%d\r\n", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4, port);
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("MBED: TCPClient IP Address is %s\r\n", eth.getIPAddress());
sprintf(buffer, "%d.%d.%d.%d", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4);
TCPSocketConnection socket;
while (socket.connect(buffer, port) < 0) {
printf("MBED: TCPCllient unable to connect to %s:%d\r\n", buffer, port);
wait(1);
}
// Test loop for multiple client connections
bool result = true;
int count_error = 0;
for (int i = 0; i < MAX_ECHO_LOOPS; i++) {
std::generate(out_buffer, out_buffer + BUFFER_SIZE, char_rand);
socket.send_all(out_buffer, BUFFER_SIZE);
int n = socket.receive(buffer, BUFFER_SIZE);
if (n > 0)
{
bool echoed = memcmp(out_buffer, buffer, BUFFER_SIZE) == 0;
result = result && echoed;
if (echoed == false) {
count_error++; // Count error messages
}
}
}
printf("MBED: Loop messages passed: %d / %d\r\n", MAX_ECHO_LOOPS - count_error, MAX_ECHO_LOOPS);
if (notify_completion_str(result, buffer)) {
socket.send_all(buffer, strlen(buffer));
}
socket.close();
eth.disconnect();
notify_completion(result);
return 0;
}
示例9: mbed_mac_address
void
tcpClient_main(intptr_t exinf) {
EthernetInterface network;
TCPSocketConnection socket;
/* syslogの設定 */
SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG)));
syslog(LOG_NOTICE, "tcpClient:");
syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf);
syslog(LOG_NOTICE, "LOG_NOTICE: Network Setting up...");
#if (USE_DHCP == 1)
if (network.init() != 0) { //for DHCP Server
#else
if (network.init(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
#endif
syslog(LOG_NOTICE, "Network Initialize Error");
return;
}
syslog(LOG_NOTICE, "Network was initialized successfully");
while (network.connect(5000) != 0) {
syslog(LOG_NOTICE, "LOG_NOTICE: Network Connect Error");
}
syslog(LOG_NOTICE, "MAC Address is %s", network.getMACAddress());
syslog(LOG_NOTICE, "IP Address is %s", network.getIPAddress());
syslog(LOG_NOTICE, "NetMask is %s", network.getNetworkMask());
syslog(LOG_NOTICE, "Gateway Address is %s", network.getGateway());
syslog(LOG_NOTICE, "Network Setup OK...");
while (socket.connect(SERVER, HTTP_PORT) < 0) {
syslog(LOG_EMERG, "Unable to connect to (%s) on port (%d)", SERVER, HTTP_PORT);
wait(1.0);
}
ClientGreet(&socket);
socket.close();
syslog(LOG_NOTICE, "program end");
}
// set mac address
void mbed_mac_address(char *mac) {
// PEACH1
mac[0] = 0x00;
mac[1] = 0x02;
mac[2] = 0xF7;
mac[3] = 0xF0;
mac[4] = 0x00;
mac[5] = 0x00;
}
示例10: app_start
void app_start(int /*argc*/, char* /*argv*/[]) {
//Sets the console baud-rate
output.baud(115200);
output.printf("In app_start()\r\n");
// This sets up the network interface configuration which will be used
// by LWM2M Client API to communicate with mbed Device server.
eth.init(); //Use DHCP
if (eth.connect() != 0) {
output.printf("Failed to form a connection!\r\n");
}
if (lwipv4_socket_init() != 0) {
output.printf("Error on lwipv4_socket_init!\r\n");
}
output.printf("IP address %s\r\n", eth.getIPAddress());
output.printf("Device name %s\r\n", MBED_ENDPOINT_NAME);
// we create our button and LED resources
auto state_resource = new StateResource();
doorIndicator.onStateChange(mbed::util::FunctionPointer1<void, DoorIndicator::WarnStatus>(state_resource, &StateResource::handle_state_change));
// Unregister button (SW3) press will unregister endpoint from connector.mbed.com
unreg_button.fall(&mbed_client, &MbedClient::test_unregister);
// Create endpoint interface to manage register and unregister
mbed_client.create_interface();
// Create Objects of varying types, see simpleclient.h for more details on implementation.
M2MSecurity* register_object = mbed_client.create_register_object(); // server object specifying connector info
M2MDevice* device_object = mbed_client.create_device_object(); // device resources object
// Create list of Objects to register
M2MObjectList object_list;
// Add objects to list
object_list.push_back(device_object);
object_list.push_back(state_resource->get_object());
// Set endpoint registration object
mbed_client.set_register_object(register_object);
mbed_client.on_object_registered(mbed::util::FunctionPointer0<void>(&doorIndicator, &DoorIndicator::init));
// Issue register command.
FunctionPointer2<void, M2MSecurity*, M2MObjectList> fp(&mbed_client, &MbedClient::test_register);
minar::Scheduler::postCallback(fp.bind(register_object,object_list));
minar::Scheduler::postCallback(&mbed_client,&MbedClient::test_update_register).period(minar::milliseconds(25000));
}
示例11: main
int main() {
eth.init();
eth.connect();
printf("IP Address: %s\n", eth.getIPAddress());
while (true) {
int response = m2xClient.postDeviceUpdates(deviceId, 2, streamNames, counts, ats, values);
printf("Response code: %d\n", response);
if (response == -1) while (true) ;
delay(5000);
}
}
示例12: test_echo_udp_client
control_t test_echo_udp_client()
{
socket_error_t err = lwipv4_socket_init();
TEST_ASSERT_EQUAL_MESSAGE(SOCKET_ERROR_NONE, err, "Failed to init LWIPv4 socket!");
printf("MBED: Initializing ethernet connection." NL);
//Use DHCP
TEST_ASSERT_EQUAL_MESSAGE(0, eth.init(), "Failed to init LWIPv4 socket!");
eth.connect();
printf("MBED: IP Address is %s" NL, eth.getIPAddress());
greentea_send_kv("target_ip", eth.getIPAddress());
memset(buffer, 0, sizeof(buffer));
port = 0;
printf("UDPClient waiting for server IP and port..." NL);
char recv_key[] = "host_port";
char port_value[] = "65325";
greentea_send_kv("host_ip", " ");
TEST_ASSERT_NOT_EQUAL_MESSAGE(0, greentea_parse_kv(recv_key, buffer, sizeof(recv_key), sizeof(buffer)), "MBED: Failed to recv/parse key value from host!");
greentea_send_kv("host_port", " ");
TEST_ASSERT_NOT_EQUAL_MESSAGE(0, greentea_parse_kv(recv_key, port_value, sizeof(recv_key), sizeof(port_value)), "MBED: Failed to recv/parse key value from host!");
sscanf(port_value, "%d", &port);
client = new UDPEchoClient(SOCKET_STACK_LWIP_IPV4);
{
mbed::util::FunctionPointer2<void, char *, uint16_t> fp(client, &UDPEchoClient::start_test);
minar::Scheduler::postCallback(fp.bind(buffer, port));
}
return CaseTimeout(25000);
}
示例13: main
int main(void)
{
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("Server IP Address is %s:%d\n", eth.getIPAddress(), ECHO_SERVER_PORT);
Thread UdpServerTask(udp_server_task, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
Thread UdpClientTask(udp_client_task, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
// Control TCP server to get mbed statistics
{
const int TELNET_SERVER_PORT = 23;
const int BUFFER_SIZE = 256;
TCPSocketServer server;
server.bind(TELNET_SERVER_PORT);
server.listen();
while (true) {
printf("Wait for new connection...\n");
TCPSocketConnection client;
server.accept(client);
client.set_blocking(false, 1500); // Timeout after (1.5)s
printf("Connection from: %s\n", client.get_address());
char buffer[BUFFER_SIZE] = { 0 };
while (true) {
int n = client.receive(buffer, sizeof(buffer));
//if (n <= 0) break;
if (n > 0) {
printf("Recv %d chars\r\n", n);
const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE - 1 : n;
buffer[buffer_string_end_index] = '\0';
// client.send_all(buffer, strlen(buffer));
if (strncmp(buffer, "stat", 4) == 0) {
sprintf(buffer, "received_packets %d\nforwarded_packets %d\nmax_queue_len %d",
received_packets, forwarded_packets, max_queue_len);
client.send_all(buffer, strlen(buffer));
// printf("%s", buffer);
}
}
//if (n <= 0) break;
}
client.close();
}
}
}
示例14: main
int main() {
Thread * thread;
pc.baud(115200);
pc.printf("\r\nStarting Mbed ...\r\n");
//Initialize the LCD
pc.printf("Initializing LCD ...\r\n");
init_LCD();
printf("Initializing USB Mass Storage ...\r\n");
printf("Inititalizing ethernet ....\r\n");
eth.init(); // Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
// After initializing the ethernet interface
// run it in its own thread
printf("Starting blinker thread ...\r\n");
thread = new Thread(led1_thread);
// Start the shell
printf("Starting debug shell ...\r\n");
shell.addCommand("ls", cmd_ls);
shell.addCommand("load", cmd_load);
shell.addCommand("mem", cmd_mem);
shell.addCommand("sensor", cmd_sensor);
shell.start(osPriorityNormal, SHELL_STACK_SIZ, shellStack);
printf("Shell now running!\r\n");
printf("Available Memory : %d\r\n", get_mem());
// Do something logical here
// other than looping
while(1) {
printf("Temperature : %d °C\r\n", htu21d.sample_ctemp());
printf("Humitdity : %d%%\r\n", htu21d.sample_humid());
wait(10);
}
thread->terminate();
delete thread;
}
示例15: main
int main (void) {
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
UDPSocket server;
server.bind(ECHO_SERVER_PORT);
Endpoint client;
char buffer[256];
while (true) {
printf("\nWait for packet...\n");
int n = server.receiveFrom(client, buffer, sizeof(buffer));
printf("Received packet from: %s\n", client.get_address());
server.sendTo(client, buffer, n);
}
}