* IPAddress issue fixed

This commit is contained in:
Danyi Dávid 2017-10-10 08:33:02 +02:00
parent a10a8ac253
commit abd91e60f5
3 changed files with 22 additions and 25 deletions

View File

@ -102,11 +102,8 @@ int connection_send(connection_t *connP,
uint8_t * buffer,
size_t length)
{
SerialUSB.println("connection_send() start");
// connP->remoteIp->printTo(SerialUSB);
IPAddress srv(192,168,14,14);
// connP->udpConnection->beginPacket(*(connP->remoteIp), connP->port);
connP->udpConnection->beginPacket(srv, connP->port);
SerialUSB.println(F("connection_send() start"));
connP->udpConnection->beginPacket(*(connP->remoteIp), connP->port);
connP->udpConnection->write(buffer, length);
connP->udpConnection->endPacket();
return 0;
@ -126,8 +123,6 @@ uint8_t lwm2m_buffer_send(void * sessionH,
return COAP_500_INTERNAL_SERVER_ERROR ;
}
SerialUSB.println("before send");
SerialUSB.println((uint32_t)connP->remoteIp);
if (-1 == connection_send(connP, buffer, length))
{
// fprintf(stderr, "#> failed sending %lu bytes\r\n", length);

View File

@ -25,12 +25,6 @@ void ArduinoClient::init() {
data.udp = new EthernetUDP();
data.udp->begin(localPort);
// debug phase
IPAddress srv(192,168,14,14);
data.udp->beginPacket(srv, 5683);
data.udp->write("HereBeDragons");
data.udp->endPacket();
// init objects
SerialUSB.println(F("*object:security"));
objArray[0] = get_security_object(uri);
@ -103,11 +97,9 @@ void ArduinoClient::doWorkStep() {
*/
SerialUSB.println(F("lwm2m_step()"));
result = lwm2m_step(lwm2mH, &step_delay);
SerialUSB.println(result, DEC);
if (result != 0)
{
SerialUSB.print(F("lwm2m_step() failed"));
SerialUSB.println(result, HEX);
exit(0);
}
@ -130,9 +122,10 @@ void ArduinoClient::doWorkStep() {
SerialUSB.println(F("doWorkStep():done"));
}
/**
* Destructor, actually this won't ever run on arduino...
*/
ArduinoClient::~ArduinoClient() {
SerialUSB.println("teardown():start");
lwm2m_close(lwm2mH);
data.udp->stop();
connection_free(data.connList);
@ -141,10 +134,15 @@ ArduinoClient::~ArduinoClient() {
free_server_object(objArray[1]);
free_object_device(objArray[2]);
free_test_object(objArray[3]);
SerialUSB.println("teardown():done");
}
/**
* called from registration.c prv_register()
*
* @param secObjInstID
* @param userData
* @return
*/
void * lwm2m_connect_server(uint16_t secObjInstID, void *userData) {
client_data_t * dataP;
char * uri;
@ -197,16 +195,16 @@ void * lwm2m_connect_server(uint16_t secObjInstID, void *userData) {
*port = 0;
port++;
IPAddress remoteIp;
if(!remoteIp.fromString(host)) {
IPAddress * remoteIp = new IPAddress();
if(!remoteIp->fromString(host)) {
DNSClient dns;
dns.begin(Ethernet.dnsServerIP());
dns.getHostByName(host, remoteIp);
dns.getHostByName(host, *remoteIp);
}
String portStr = port;
newConnP = connection_create(dataP->connList, dataP->udp, &remoteIp, portStr.toInt());
newConnP = connection_create(dataP->connList, dataP->udp, remoteIp, portStr.toInt());
if (newConnP == nullptr) {
SerialUSB.println(F("Connection creation failed"));
}
@ -219,7 +217,12 @@ void * lwm2m_connect_server(uint16_t secObjInstID, void *userData) {
return (void *)newConnP;
};
/**
* called from
*
* @param sessionH
* @param userData
*/
void lwm2m_close_connection(void *sessionH, void *userData) {
client_data_t * app_data;
connection_t * targetP;

View File

@ -411,7 +411,6 @@ int transaction_send(lwm2m_context_t * contextP,
maxRetriesReached = true;
}
}
lwm2m_printf("max");
if (transacP->ack_received || maxRetriesReached)
{