Error when using Wifi CC3000 and Wiz820io Ethernet at the sa

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bougs
 
Posts: 14
Joined: Mon Sep 15, 2014 11:56 pm

Error when using Wifi CC3000 and Wiz820io Ethernet at the sa

Post by bougs »

Hello,

I have this simple sketch:

Code: Select all

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include "SPI.h"
#include "Ethernet.h"

void setup() {}

void loop() {}
This sketch compiles fine if I take out #include "Ethernet.h" but throws the following errors when being included:

Code: Select all

C:\Program Files (x86)\Arduino\libraries\Ethernet\src\utility\socket.cpp: In function 'uint8_t socket(SOCKET, uint8_t, uint16_t, uint8_t)':
C:\Program Files (x86)\Arduino\libraries\Ethernet\src\utility\socket.cpp:14:12: error: 'close' was not declared in this scope
     close(s);
            ^
if I include ethernet.h before cc3000.h then i get the following (worse) errors:

Code: Select all

C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp: In member function 'char sntp::GetNTPServerList(const char**, uint32_t*, int)':
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:371:64: error: 'gethostbyname' was not declared in this scope
    gethostbyname(*ntpPoolName, strlen(*ntpPoolName), &ntpServer);
                                                                ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp: In member function 'bool sntp::SNTP_GetTime(int, uint32_t*)':
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:393:2: error: 'sockaddr_in' was not declared in this scope
  sockaddr_in   socketAddr;
  ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:393:16: error: expected ';' before 'socketAddr'
  sockaddr_in   socketAddr;
                ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:394:2: error: 'socklen_t' was not declared in this scope
  socklen_t   sockLen;
  ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:394:14: error: expected ';' before 'sockLen'
  socklen_t   sockLen;
              ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:406:10: error: 'socketAddr' was not declared in this scope
  memset(&socketAddr, 0, sizeof(sockaddr_in));
          ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:407:26: error: 'AF_INET' was not declared in this scope
  socketAddr.sin_family = AF_INET;
                          ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:409:39: error: 'htons' was not declared in this scope
  socketAddr.sin_port = htons(SNTP_PORT);
                                       ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:422:2: error: 'sockLen' was not declared in this scope
  sockLen = sizeof(sockaddr_in);
  ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:423:76: error: 'sockaddr' was not declared in this scope
  byteCount = sendto(sntpSocket, &sntp_message, sizeof(SNTP_Message_t), 0, (sockaddr*)&socketAddr, sockLen);
                                                                            ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:423:85: error: expected primary-expression before ')' token
  byteCount = sendto(sntpSocket, &sntp_message, sizeof(SNTP_Message_t), 0, (sockaddr*)&socketAddr, sockLen);
                                                                                     ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:435:26: error: 'SOL_SOCKET' was not declared in this scope
   setsockopt(sntpSocket, SOL_SOCKET, SOCKOPT_RECV_TIMEOUT, &recvTimeout, (socklen_t)sizeof(recvTimeout));
                          ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:435:38: error: 'SOCKOPT_RECV_TIMEOUT' was not declared in this scope
   setsockopt(sntpSocket, SOL_SOCKET, SOCKOPT_RECV_TIMEOUT, &recvTimeout, (socklen_t)sizeof(recvTimeout));
                                      ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:435:85: error: expected ')' before 'sizeof'
   setsockopt(sntpSocket, SOL_SOCKET, SOCKOPT_RECV_TIMEOUT, &recvTimeout, (socklen_t)sizeof(recvTimeout));
                                                                                     ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:435:104: error: 'setsockopt' was not declared in this scope
   setsockopt(sntpSocket, SOL_SOCKET, SOCKOPT_RECV_TIMEOUT, &recvTimeout, (socklen_t)sizeof(recvTimeout));
                                                                                                        ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:437:88: error: expected primary-expression before ')' token
   byteCount = recvfrom(sntpSocket, &sntp_message, sizeof(SNTP_Message_t), 0, (sockaddr*)&socketAddr, &sockLen);
                                                                                        ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:452:74: error: 'htonl' was not declared in this scope
    sntp_message.tsReceive.seconds  = htonl(sntp_message.tsReceive.seconds);
                                                                          ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp: In member function 'bool sntp::UpdateNTPTime()':
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:515:2: error: 'sockaddr_in' was not declared in this scope
  sockaddr_in   socketAddr;
  ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:515:16: error: expected ';' before 'socketAddr'
  sockaddr_in   socketAddr;
                ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:528:22: error: 'AF_INET' was not declared in this scope
  sntpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
                      ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:528:31: error: 'SOCK_DGRAM' was not declared in this scope
  sntpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
                               ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:528:43: error: 'IPPROTO_UDP' was not declared in this scope
  sntpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
                                           ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:534:12: error: 'socketAddr' was not declared in this scope
    memset(&socketAddr, 0, sizeof(sockaddr_in));     //zero it
            ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:538:41: error: 'htons' was not declared in this scope
    socketAddr.sin_port = htons(localPort);                     //well-known NTP port number, assigned by IANA
                                         ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:540:42: error: 'sockaddr' was not declared in this scope
    portIsBound = (0 == bind(sntpSocket, (sockaddr*)&socketAddr, sizeof(sockaddr_in)));
                                          ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:540:51: error: expected primary-expression before ')' token
    portIsBound = (0 == bind(sntpSocket, (sockaddr*)&socketAddr, sizeof(sockaddr_in)));
                                                   ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:540:84: error: 'bind' was not declared in this scope
    portIsBound = (0 == bind(sntpSocket, (sockaddr*)&socketAddr, sizeof(sockaddr_in)));
                                                                                    ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:588:60: error: 'htonl' was not declared in this scope
       uint32_t serverAddr = htonl(*(uint32_t*)pServerList++);
                                                            ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:645:26: error: 'closesocket' was not declared in this scope
    closesocket(sntpSocket);
                          ^
C:\Users\home\Documents\Arduino\libraries\Adafruit_CC3000\utility\sntp.cpp:651:26: error: 'closesocket' was not declared in this scope
    closesocket(sntpSocket);
                          ^
How do I resolve these conflicts/issues?

Setup Info:
Arduino DUE
CC3000 Wifi Shield
Wiz820io Ethernet

All Wifi examples that come with the library compile and work fine.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Error when using Wifi CC3000 and Wiz820io Ethernet at th

Post by adafruit_support_bill »

Both the CC3000 and Ethernet libraries implement a version of the sockets API. Since sockets is a long-time standard API, most, if not all of the function names in both libraries are going to be the same. I don't think it is possible to combine the two without a major re-write of one of them.

User avatar
bougs
 
Posts: 14
Joined: Mon Sep 15, 2014 11:56 pm

Re: Error when using Wifi CC3000 and Wiz820io Ethernet at th

Post by bougs »

adafruit_support_bill wrote:Both the CC3000 and Ethernet libraries implement a version of the sockets API. Since sockets is a long-time standard API, most, if not all of the function names in both libraries are going to be the same. I don't think it is possible to combine the two without a major re-write of one of them.
Thanks for pointing me in the right direction. The changes necessary weren't as bad as you thought. All you need to do is rename socket.ccp/h to CC3000_socket.cpp/h and update all the include delcarations in all the files.

here is a patch file before renaming the socket file:

Code: Select all

--- examples/ChatServer/ChatServer.ino	Wed Aug 20 15:03:16 2014
+++ examples/ChatServer/ChatServer.ino	Tue Sep 30 21:30:06 2014
@@ -71 +71 @@
-#include "utility/socket.h"
+#include "utility/CC3000_socket.h"
--- examples/EchoServer/EchoServer.ino	Wed Aug 20 15:03:16 2014
+++ examples/EchoServer/EchoServer.ino	Tue Sep 30 21:30:17 2014
@@ -77 +77 @@
-#include "utility/socket.h"
+#include "utility/CC3000_socket.h"
--- examples/HTTPServer/HTTPServer.ino	Wed Aug 20 15:03:16 2014
+++ examples/HTTPServer/HTTPServer.ino	Tue Sep 30 21:30:24 2014
@@ -58 +58 @@
-#include "utility/socket.h"
+#include "utility/CC3000_socket.h"
--- utility/cc3000_common.cpp	Wed Aug 20 15:03:16 2014
+++ utility/cc3000_common.cpp	Tue Sep 30 21:30:28 2014
@@ -55 +55 @@
-#include "socket.h"
+#include "CC3000_socket.h"
--- utility/evnt_handler.cpp	Wed Aug 20 15:03:16 2014
+++ utility/evnt_handler.cpp	Tue Sep 30 21:30:36 2014
@@ -59 +59 @@
-#include "socket.h"
+#include "CC3000_socket.h"
--- utility/evnt_handler.h	Wed Aug 20 15:03:16 2014
+++ utility/evnt_handler.h	Tue Sep 30 21:33:25 2014
@@ -46 +46 @@
-#include "socket.h"
+#include "CC3000_socket.h"
--- utility/netapp.cpp	Wed Aug 20 15:03:16 2014
+++ utility/netapp.cpp	Tue Sep 30 21:33:29 2014
@@ -46 +46 @@
-#include "socket.h"
+#include "CC3000_socket.h"
--- utility/nvmem.cpp	Wed Aug 20 15:03:16 2014
+++ utility/nvmem.cpp	Tue Sep 30 21:30:47 2014
@@ -61 +61 @@
-#include "socket.h"
+#include "CC3000_socket.h"
--- utility/sntp.h	Wed Aug 20 15:03:16 2014
+++ utility/sntp.h	Tue Sep 30 21:44:04 2014
@@ -275,2 +275,2 @@
-#include "utility/socket.h"
-#include "utility/netapp.h"
+#include "CC3000_socket.h"
+#include "netapp.h"
--- utility/socket.cpp	Wed Aug 20 15:03:16 2014
+++ utility/socket.cpp	Tue Sep 30 21:26:44 2014
@@ -57 +57 @@
-#include "socket.h"
+#include "CC3000_socket.h"
--- utility/socket.h	Wed Aug 20 15:03:16 2014
+++ utility/socket.h	Tue Sep 30 21:43:31 2014
@@ -3 +3 @@
-*  socket.h  - CC3000 Host Driver Implementation.
+*  CC3000_socket.h  - CC3000 Host Driver Implementation.
@@ -43,2 +43,2 @@
-#ifndef __SOCKET_H__
-#define __SOCKET_H__
+#ifndef __CC3000_SOCKET_H__
+#define __CC3000_SOCKET_H__
--- utility/wlan.cpp	Wed Aug 20 15:03:16 2014
+++ utility/wlan.cpp	Tue Sep 30 21:30:42 2014
@@ -54 +54 @@
-#include "socket.h"
+#include "CC3000_socket.h"
--- Adafruit_CC3000.cpp	Wed Aug 20 15:03:16 2014
+++ Adafruit_CC3000.cpp	Tue Sep 30 21:29:53 2014
@@ -32 +32 @@
-#include "utility/socket.h"
+#include "utility/CC3000_socket.h"
--- Adafruit_CC3000_Server.cpp	Wed Aug 20 15:03:16 2014
+++ Adafruit_CC3000_Server.cpp	Tue Sep 30 21:29:59 2014
@@ -17 +17 @@
-#include "utility/socket.h"
+#include "utility/CC3000_socket.h"
I also made an additional change to sntp.h (shown above) to remove the unnecessary folder specifier

With the changes my skecth example in the original post compiles fine and the buildtest example works perfectly.

Can I submit these changes to https://github.com/adafruit/Adafruit_CC3000_Library? This is a relatively safe change that could save people from encountering this issue in the future.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Error when using Wifi CC3000 and Wiz820io Ethernet at th

Post by adafruit_support_bill »

Excellent! Thanks for the follow-up. I'll refer this to the maintainers of the library.

User avatar
bougs
 
Posts: 14
Joined: Mon Sep 15, 2014 11:56 pm

Re: Error when using Wifi CC3000 and Wiz820io Ethernet at th

Post by bougs »

adafruit_support_bill wrote:Excellent! Thanks for the follow-up. I'll refer this to the maintainers of the library.
Here is my pull request.

User avatar
bougs
 
Posts: 14
Joined: Mon Sep 15, 2014 11:56 pm

Re: Error when using Wifi CC3000 and Wiz820io Ethernet at th

Post by bougs »

Just to close this out on this forum. Here is what the developer of the cc3k library said on github:
Thanks for sending the pull request and tracking down the conflict with using both libraries. This is kind of tricky since we have a lot of folks using the library today who might be broken if we change the file name. It's pretty common to use the low level socket API once you need to do more advanced things with the CC3k, and unfortunately folks using it would be broken when they update the library and try to compile their sketch. It's an easy fix to change the file name but is painful to track down what the new file name should be.

The other issue is that we grab the socket.cpp & .h files from TI's 'reference' driver code and try to keep them as close to TI's code as possible. This makes it easier to integrate firmware updates from them into the library, but changing the name would cause a little more pain.

Since using the CC3k and ethernet shield together isn't super common (but sounds pretty cool!) and these changes could cause problems for library users today I'll close this request without pulling it into the main library. However it's great that you tracked down a fix so folks who run into the same issue can find your fork and this issue to see an easy workaround. Thanks again for contributing!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”