star297
(Paul Staron)
February 21, 2020, 10:09am
1
Just when everything works with no warnings, next day they’re back
Can anyone help with this:
return ((TLSSocket*)_socket)->connect(host, port);
printf("IP address: %s\n", network->get_ip_address());
printf("Netmask: %s\n", network->get_netmask());
printf("Gateway: %s\n", network->get_gateway());
if ((r = socket->connect(FirebaseID, 443)) != NSAPI_ERROR_OK) {
printf("TLS socket connect failed (%d)\n", r);
}
The above 5 lines give these string based depreciated warnings.
Warning: ‘get_netmask’ is deprecated: String-based APIs are deprecated [since mbed-os-5.15] [-Wdeprecated-declarations]
Considering I’m the thickest person on the planet, could someone give me an example to correct these please?
Many thanks
Paul
Pekka01
(Pekka Saavalainen)
February 21, 2020, 11:30am
2
Hi Paul,
If network is NetworkInterface then you should give pointer to
SocketAddress a;
net->get_ip_address(&a);
printf(“IP address: %s\n”, a.get_ip_address() ? a.get_ip_address() : “None”);
net->get_netmask(&a);
printf(“Netmask: %s\n”, a.get_ip_address() ? a.get_ip_address() : “None”);
net->get_gateway(&a);
printf(“Gateway: %s\n”, a.get_ip_address() ? a.get_ip_address() : “None”);
I hope this helps. If not hopefully somebody who knows better answers.
Regards,
Pekka
star297
(Paul Staron)
March 1, 2020, 2:57pm
3
Thanks Pekka,
Yes your example worked, but had a couple other ‘stringy API’ problems and Jan kamidra had the answers:
How to get IP, NETMASK. GATEWAY:
SocketAddress ip = "192.168.1.1";
SocketAddress mask = "255.255.255.0";
SocketAddress gateway = "10.0.1.138";
eth.set_network(ip,mask,gateway);
//or retype string
eth.set_network((SocketAddress)"192.168.1.1",(SocketAddress)"255.255.255.0",(SocketAddress)"10.0.1.138");
//or retype macro
eth_stat = eth.set_network((SocketAddress)IP,(SocketAddress)MASK,(SocketAddress)GATEWAY);
add to get:
the first one is ok from my point of view. The .get_ip_address
was change to same design like .set_ip_address
. It return nsapi_error
and the address is returned via object of SocketAddress which need to be placed as input parameter and then read the content of that object.
SocketAddress check;
eth.get_ip_address(&check);
printf("IP address: %s\n", check.get_ip_address() ? check.get_ip_address() : "None");
eth.get_netmask(&check);
printf("Netmask: %s\n", check.get_ip_address() ? check.get_ip_address() : "None");
eth.get_gateway(&check);
printf("Gateway: %s\n", check.get_ip_address() ? check.get_ip_address() : "None");
Now no string based errors