* updated to nbiot driver
This commit is contained in:
parent
f65ffde252
commit
174971097f
@ -1,5 +1,5 @@
|
|||||||
set(ARDUINO_BASE_LIBDIR /opt/arduino-1.8.5)
|
set(ARDUINO_BASE_LIBDIR /opt/arduino-1.8.5)
|
||||||
set(ARDUINO_SAMD_DIR $ENV{HOME}/.arduino15/packages/arduino/hardware/samd/1.6.16)
|
set(ARDUINO_SAMD_DIR $ENV{HOME}/.arduino15/packages/arduino/hardware/samd/1.6.17)
|
||||||
|
|
||||||
set(ARDUINO_INCLUDE_DIRS
|
set(ARDUINO_INCLUDE_DIRS
|
||||||
${ARDUINO_SAMD_DIR}/cores/arduino
|
${ARDUINO_SAMD_DIR}/cores/arduino
|
||||||
|
|||||||
@ -17,21 +17,19 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <Dns.h>
|
#include <Sodaq_nbIOT.h>
|
||||||
#include <Ethernet.h>
|
|
||||||
#include <IPAddress.h>
|
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
|
||||||
|
|
||||||
connection_t * connection_find(connection_t * connList,
|
connection_t * connection_find(connection_t * connList,
|
||||||
EthernetUDP * udpConnection)
|
int sock)
|
||||||
{
|
{
|
||||||
connection_t * connP;
|
connection_t * connP;
|
||||||
|
|
||||||
connP = connList;
|
connP = connList;
|
||||||
while (connP != nullptr)
|
while (connP != nullptr)
|
||||||
{
|
{
|
||||||
if (connP->udpConnection == udpConnection)
|
if (connP->sock == sock)
|
||||||
{
|
{
|
||||||
return connP;
|
return connP;
|
||||||
}
|
}
|
||||||
@ -43,8 +41,9 @@ connection_t * connection_find(connection_t * connList,
|
|||||||
|
|
||||||
|
|
||||||
connection_t * connection_new_incoming(connection_t * connList,
|
connection_t * connection_new_incoming(connection_t * connList,
|
||||||
EthernetUDP * udpConnection,
|
int sock,
|
||||||
IPAddress * remoteIp,
|
Sodaq_nbIOT * nbIOT,
|
||||||
|
char * remoteIpStr,
|
||||||
uint16_t port)
|
uint16_t port)
|
||||||
{
|
{
|
||||||
connection_t * connP;
|
connection_t * connP;
|
||||||
@ -52,32 +51,33 @@ connection_t * connection_new_incoming(connection_t * connList,
|
|||||||
connP = (connection_t *)malloc(sizeof(connection_t));
|
connP = (connection_t *)malloc(sizeof(connection_t));
|
||||||
if (connP != nullptr)
|
if (connP != nullptr)
|
||||||
{
|
{
|
||||||
connP->udpConnection = udpConnection;
|
int remoteIpLen = strlen(remoteIpStr)+1;
|
||||||
connP->remoteIp = remoteIp;
|
connP->remoteIpStr = (char*)malloc(remoteIpLen);
|
||||||
|
// memset(connP->remoteIpStr, 0, remoteIpLen);
|
||||||
|
strncpy(connP->remoteIpStr, remoteIpStr, remoteIpLen);
|
||||||
|
|
||||||
|
connP->nbIOT = nbIOT;
|
||||||
|
connP->sock = sock;
|
||||||
connP->port = port;
|
connP->port = port;
|
||||||
connP->next = connList;
|
connP->next = connList;
|
||||||
|
|
||||||
|
SerialUSB.print(F("connP->remoteIpStr: "));
|
||||||
|
SerialUSB.println(connP->remoteIpStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return connP;
|
return connP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo add some sort of sanity checking to see if its possible to connect
|
|
||||||
* @param connList
|
|
||||||
* @param udpConnection
|
|
||||||
* @param remoteIp
|
|
||||||
* @param port
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
connection_t * connection_create(connection_t * connList,
|
connection_t * connection_create(connection_t * connList,
|
||||||
EthernetUDP * udpConnection,
|
int sock,
|
||||||
IPAddress * remoteIp,
|
Sodaq_nbIOT * nbIOT,
|
||||||
|
char * remoteIpStr,
|
||||||
uint16_t port)
|
uint16_t port)
|
||||||
{
|
{
|
||||||
connection_t * connP = nullptr;
|
connection_t * connP = nullptr;
|
||||||
|
if(*remoteIpStr != NULL) {
|
||||||
if(*remoteIp != 0) {
|
connP = connection_new_incoming(connList, sock, nbIOT, remoteIpStr, port);
|
||||||
connP = connection_new_incoming(connList, udpConnection, remoteIp, port);
|
|
||||||
}
|
}
|
||||||
return connP;
|
return connP;
|
||||||
}
|
}
|
||||||
@ -90,6 +90,7 @@ void connection_free(connection_t * connList)
|
|||||||
connection_t * nextP;
|
connection_t * nextP;
|
||||||
|
|
||||||
nextP = connList->next;
|
nextP = connList->next;
|
||||||
|
free(connList->remoteIpStr);
|
||||||
free(connList);
|
free(connList);
|
||||||
|
|
||||||
connList = nextP;
|
connList = nextP;
|
||||||
@ -101,10 +102,7 @@ int connection_send(connection_t *connP,
|
|||||||
uint8_t * buffer,
|
uint8_t * buffer,
|
||||||
size_t length)
|
size_t length)
|
||||||
{
|
{
|
||||||
SerialOut.println(F("connection_send() start"));
|
connP->nbIOT->sendSocket(connP->sock, connP->remoteIpStr, connP->port, buffer, length);
|
||||||
connP->udpConnection->beginPacket(*(connP->remoteIp), connP->port);
|
|
||||||
connP->udpConnection->write(buffer, length);
|
|
||||||
connP->udpConnection->endPacket();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,13 +116,11 @@ uint8_t lwm2m_buffer_send(void * sessionH,
|
|||||||
|
|
||||||
if (connP == nullptr)
|
if (connP == nullptr)
|
||||||
{
|
{
|
||||||
// fprintf(stderr, "#> failed sending %lu bytes, missing connection\r\n", length);
|
|
||||||
return COAP_500_INTERNAL_SERVER_ERROR ;
|
return COAP_500_INTERNAL_SERVER_ERROR ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-1 == connection_send(connP, buffer, length))
|
if (-1 == connection_send(connP, buffer, length))
|
||||||
{
|
{
|
||||||
// fprintf(stderr, "#> failed sending %lu bytes\r\n", length);
|
|
||||||
return COAP_500_INTERNAL_SERVER_ERROR ;
|
return COAP_500_INTERNAL_SERVER_ERROR ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,9 +23,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <liblwm2m.h>
|
#include <liblwm2m.h>
|
||||||
|
|
||||||
#include <EthernetUdp.h>
|
|
||||||
#include <serialout.h>
|
|
||||||
|
|
||||||
#define LWM2M_STANDARD_PORT_STR "5683"
|
#define LWM2M_STANDARD_PORT_STR "5683"
|
||||||
#define LWM2M_STANDARD_PORT 5683
|
#define LWM2M_STANDARD_PORT 5683
|
||||||
#define LWM2M_DTLS_PORT_STR "5684"
|
#define LWM2M_DTLS_PORT_STR "5684"
|
||||||
@ -36,26 +33,29 @@
|
|||||||
typedef struct _connection_t
|
typedef struct _connection_t
|
||||||
{
|
{
|
||||||
struct _connection_t * next;
|
struct _connection_t * next;
|
||||||
EthernetUDP * udpConnection;
|
int sock;
|
||||||
IPAddress * remoteIp;
|
Sodaq_nbIOT * nbIOT;
|
||||||
|
char * remoteIpStr;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
} connection_t;
|
} connection_t;
|
||||||
|
|
||||||
//int create_socket(const char * portStr, int ai_family);
|
//int create_socket(const char * portStr, int ai_family);
|
||||||
|
|
||||||
connection_t * connection_find(connection_t * connList,
|
connection_t * connection_find(connection_t * connList,
|
||||||
EthernetUDP * udpConnection);
|
int sock);
|
||||||
connection_t * connection_new_incoming(connection_t * connList,
|
connection_t * connection_new_incoming(connection_t * connList,
|
||||||
EthernetUDP * udpConnection,
|
int sock,
|
||||||
IPAddress * remoteIp,
|
Sodaq_nbIOT * nbIOT,
|
||||||
|
char * remoteIp,
|
||||||
uint16_t port);
|
uint16_t port);
|
||||||
connection_t * connection_create(connection_t * connList,
|
connection_t * connection_create(connection_t * connList,
|
||||||
EthernetUDP * udpConnection,
|
int sock,
|
||||||
IPAddress * remoteIp,
|
Sodaq_nbIOT * nbIOT,
|
||||||
|
char * remoteIp,
|
||||||
uint16_t port);
|
uint16_t port);
|
||||||
|
|
||||||
void connection_free(connection_t * connList);
|
void connection_free(connection_t * connList);
|
||||||
|
|
||||||
int connection_send(connection_t *connP, uint8_t * buffer, size_t length);
|
int connection_send(connection_t *connP, char * buffer, size_t length);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -11,7 +11,7 @@ if(DTLS)
|
|||||||
set(SHARED_SOURCES
|
set(SHARED_SOURCES
|
||||||
${SHARED_SOURCES}
|
${SHARED_SOURCES}
|
||||||
${TINYDTLS_SOURCES}
|
${TINYDTLS_SOURCES}
|
||||||
${SHARED_SOURCES_DIR}/dtlsconnection.c)
|
${SHARED_SOURCES_DIR}/dtlsconnection.cpp)
|
||||||
|
|
||||||
set(SHARED_INCLUDE_DIRS
|
set(SHARED_INCLUDE_DIRS
|
||||||
${SHARED_SOURCES_DIR}
|
${SHARED_SOURCES_DIR}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user