Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino Library does not work on ESP8266 if SPI.h is not included #30

Closed
jpwsutton opened this issue Feb 26, 2016 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@jpwsutton
Copy link
Member

In IPStack.h it tries to include SPI.h (as this is required by normal Arduinos). However, if the user is using the ESP8266 Arduino core (https://github.com/esp8266/Arduino) and does not need to include SPI.h then a compile error will be thrown:

In file included from PahoESP8266.ino:6:0:
/Users/jamessutton/Documents/Arduino/libraries/MQTTClient/IPStack.h:22:19: fatal error: SPI.h: No such file or directory
   #include <SPI.h>
                   ^
compilation terminated.
Error compiling.

Because the ESP8266 does not require SPI for it's networking functions, a user is unlikely to want to include the SPI library just to get their sketch to compile.

I modified my local copy of IPStack.h to only attempt to include SPI.h if WiFi_h has not been defined. This is because, the ESP8266WiFi Library has defined it so should be a good indicator as to whether the client is being compiled for the ESP8266.

#ifndef WiFi_h
  #include <SPI.h>
#endif

I've tested this and it seems to work fine on my own machine / ESP8266, but I wouldn't say I'm confident enough with C to want to make the commit / Pull request myself in case this is a terrible idea, so thought it best to open as an issue.

Other than that, the library works great on the ESP8266, I've modified the Example sketch to work with it here: https://gist.github.com/jpwsutton/d364f46a54575f359fbe#file-paho_arduino_esp8266-ino

@icraggs icraggs added this to the 1.1 milestone Jul 7, 2017
@icraggs icraggs added the bug label Jul 7, 2017
@icraggs icraggs self-assigned this Jul 7, 2017
icraggs pushed a commit that referenced this issue Jul 7, 2017
@icraggs
Copy link
Contributor

icraggs commented Jul 7, 2017

I've made your suggested change to IPStack.h. Thanks.

@icraggs icraggs closed this as completed Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants