pubnub / arduino

The Official PubNub Arduino-based API!
Other
105 stars 49 forks source link

Sample Sketch doesn't compile due to code error #15

Closed MpeStuntPilot closed 7 years ago

MpeStuntPilot commented 7 years ago

The latest sample sketch doesn't compile due to a number of issues. The first issue is in line 17 of the PubNubWifi101 sketch - #define Pubnub_BASE_CLIENT WiFiClient In , it is expecting the #define to be #define PubNub_BASE_CLIENT EthernetClient -- note that Pubnub and PubNub have different cases.

There are other errors too, and tons of warnings.
I have tried the other examples, none of them compile. There are undefined references to various string compare functions.

I'm using Arduino 1.6.13 on Ubuntu 14.04. The PubNub libraries and sample sketches were obtained today from GitHub.

vveljko commented 7 years ago

The issue with examples and wrong case of N is fixed. Thank you for reporting this.

As for the problems with string compare functions, those happen on some Arduino platforms/boards which don't have valid C library support. What boards are you using and what undefined references are reported to you?

MpeStuntPilot commented 7 years ago

Wow, you respond quickly!

I did try compiling with other platforms selected as the target. Those worked! I wouldn't have never guessed they all don't use a common Arduino basic core library.

The platform I am using is based on the ESP8266. Its has a very low cost 32 bit processor, with WiFi, and the ability to function as a web client, server, and access point. The library can be downloaded to the Arduino IDE by using File -> Preferences -> Setting Tab -> "Additional Boards Manager URLs : http://arduino.esp8266.com/stable/package_esp8266com_index.json ". Pressing OK after this point will load in the new library and present new options under the Tools -> Board: menu choice. The particular board I have is the "NodeMCU 1.0 (ESP-12E Module)". There are many choices in the ESP8266 family, and they seem to all have the same string compare functions missing. The functions I see missing are strncasecmp() and strspn().

Thanks for your quick reply!

On Wed, Dec 7, 2016 at 3:07 PM, vveljko notifications@github.com wrote:

The issue with examples and wrong case of N is fixed. Thank you for reporting this.

As for the problems with string compare functions, those happen on some Arduino platforms/boards which don't have valid C library support. What boards are you using and what undefined references are reported to you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pubnub/arduino/issues/15#issuecomment-265602732, or mute the thread https://github.com/notifications/unsubscribe-auth/AXTzO88wipgAjgLPv-5c0zk1OuFB0uWCks5rFzxDgaJpZM4LHEjw .

-- Regards,

Marcus Escobosa marcusescobosa@gmail.com

vveljko commented 7 years ago

We are aware of the problem w/ESP8266. Unfortunately, their support for C library is a moving target, we can't make a solution that works for all versions of their Arduino support... OTOH, we don't like the idea of writing those functions ourselves and not using C library versions, because that wastes memory, which is not what you do in embedded systems. So, we don't have a good solution for this yet.

Until we figure this out, you can put these into PubNubDefs.h:

inline size_t strspn(const char* cs, const char* ct) {
  size_t n;
  for (n=0; *cs; cs++, n++) {
    const char* p;
    for (p=ct; *p && *p != *cs; ++p) {
      continue;
    }
    if (*p != '\0') {
      break;
    }
  }
  return n;
}

#include <ctype.h>
inline int strncasecmp(const char *s1, const char *s2, size_t n) {
  size_t i = 0;
  while (i < n) {
    int diff = tolower(s1[i]) - tolower(s2[i]);
    if (diff != 0) {
      return diff;
    } 
    if (s1[i] == '\0') {
      return diff;
    }
    ++i;
  }
  return 0;
}
MpeStuntPilot commented 7 years ago

Thanks for the fix, I'll give it a try. I looked into the ESP8266 tools installation, and found the functions. Somehow, they didn't seem to completely resolve the undefined reference problem, even with small changes to the pubnub code. It also seems that the tools have multiple string.h files too, just to add to the confusion.

On Thu, Dec 8, 2016 at 6:19 AM, vveljko notifications@github.com wrote:

We are aware of the problem w/ESP8266. Unfortunately, their support for C library is a moving target, we can't make a solution that works for all versions of their Arduino support... OTOH, we don't like the idea of writing those functions ourselves and not using C library versions, because that wastes memory, which is not what you do in embedded systems. So, we don't have a good solution for this yet.

Until we figure this out, you can put these into PubNubDefs.h:

inline size_t strspn(const char cs, const char ct) { size_t n; for (n=0; cs; cs++, n++) { const char p; for (p=ct; p && p != cs; ++p) { continue; } if (p != '\0') { break; } } return n; }

include

inline int strncasecmp(const char s1, const char s2, size_t n) { size_t i = 0; while (i < n) { int diff = tolower(s1[i]) - tolower(s2[i]); if (diff != 0) { return diff; } if (s1[i] == '\0') { return diff; } ++i; } return 0; }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pubnub/arduino/issues/15#issuecomment-265750472, or mute the thread https://github.com/notifications/unsubscribe-auth/AXTzO_PDfTdo-Qw00atc4usQtLG4CxrAks5rGBIFgaJpZM4LHEjw .

-- Regards,

Marcus Escobosa marcusescobosa@gmail.com

MpeStuntPilot commented 7 years ago

I put in the changes and code compiles.

I work for Insteon, and we use PubNub for home automation in our hubs. We have just under 100K hubs in customer hands, and see active traffic from about 60K of them on a typical day. I have been using our pubkey, subkey, and the gac-hub2 channel to run the PubNubWifi101 example sketch. I also found the DBGprintln functions, and I'm using those to continue to find why I can't publish successfully.

I found the code that generates the GET request using the pubsub.pubnub.com host. The debug messages show that a status code of 4xx is being received, and it should be a 2xx for a good message. This causes the publish to fail. My question is what could be the cause. If the pubkey or subkey or channel were wrong, would that cause this? Is it a bad host address? If you can provide some pointers that would help alot. I'm new to pubnub programming, and don't know how pubnub responds to errors in the requests being sent to it.

Thanks

On Thu, Dec 8, 2016 at 6:19 AM, vveljko notifications@github.com wrote:

We are aware of the problem w/ESP8266. Unfortunately, their support for C library is a moving target, we can't make a solution that works for all versions of their Arduino support... OTOH, we don't like the idea of writing those functions ourselves and not using C library versions, because that wastes memory, which is not what you do in embedded systems. So, we don't have a good solution for this yet.

Until we figure this out, you can put these into PubNubDefs.h:

inline size_t strspn(const char cs, const char ct) { size_t n; for (n=0; cs; cs++, n++) { const char p; for (p=ct; p && p != cs; ++p) { continue; } if (p != '\0') { break; } } return n; }

include

inline int strncasecmp(const char s1, const char s2, size_t n) { size_t i = 0; while (i < n) { int diff = tolower(s1[i]) - tolower(s2[i]); if (diff != 0) { return diff; } if (s1[i] == '\0') { return diff; } ++i; } return 0; }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pubnub/arduino/issues/15#issuecomment-265750472, or mute the thread https://github.com/notifications/unsubscribe-auth/AXTzO_PDfTdo-Qw00atc4usQtLG4CxrAks5rGBIFgaJpZM4LHEjw .

-- Regards,

Marcus Escobosa marcusescobosa@gmail.com

crimsonred commented 7 years ago

@MpeStuntPilot

Can you let us know the full 4xx response that you get and the publish URI with the payload (without your sub and pub keys).

Also please contact us on support@pubnub.com

Thanks

vveljko commented 7 years ago

Contacting our support at support@pubnub.com is the way to go, really, they make sure all your problems are taken care of by whoever can tackle it best.

A frequent problem is forgetting to quote the string, for example:

    client = PubNub.publish("my-channel", "Hello there");

This won't work, it's not a valid JSON, you need to:

    client = PubNub.publish("my-channel", "\"Hello there\"");

But, it can be any number of reasons, so, please get the whole HTTP response and send it to us.

jshaw commented 7 years ago

@vveljko thanks for the interim solution you posted above. It seemed to allow me to publish to pubnub however it seems that as soon as the string which I have in JSON format is published I get Exception(3). I've logged another ticket here #16