pubnub / arduino

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

publishing error on PubNubWifi101.ino using MKR1000 board #17

Closed kmf909 closed 7 years ago

kmf909 commented 7 years ago

Hi

as per title, I'm using MKR1000 board, i can verify and upload the sketch but on serial monitor it pop up publishing error. below is the sketch

include

include

define PubNub_BASE_CLIENT WiFiClient

include

static char ssid[] = ""; // your network SSID (name) static char pass[] = ""; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status

const static char pubkey[] = "pub-c-b5092f02-f467-4795-b5ba-97286b6cb961"; //PubNub wifi101 Dev const static char subkey[] = "sub-c-b60400ce-23f6-11e7-bd07-02ee2ddab7fe"; const static char channel[] = "hello_world";

void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("Serial set up");

// attempt to connect using WPA2 encryption: Serial.println("Attempting to connect to WPA network..."); status = WiFi.begin(ssid, pass);

// if you're not connected, stop here: if ( status != WL_CONNECTED) { Serial.println("Couldn't get a wifi connection"); while (true); } else { Serial.print("WiFi connecting to SSID: "); Serial.println(ssid);

PubNub.begin(pubkey, subkey);
Serial.println("PubNub set up");

} }

void loop() {

/ Publish /

WiFiClient *client;

char msg[] = "\"running\"";

client = PubNub.publish(channel, msg);

if (!client) { Serial.println("publishing error"); delay(1000); return; } client->stop(); }

vveljko commented 7 years ago

I'm not sure if there is some "pasting problem" (i.e. your code might not be like this, it just got pasted like that), but, this can't work:

char msg[] = ""running"";

you need to:

char msg[] = "\"running\"";
wellard commented 7 years ago

hi,

i have same problem with this code. im using MKR1000 and already changed the code into this:

char msg [ ] = "\"Yo!\"";

but the serial still appeared 'publishing error'.

And secondly, i tried to leave the board overnight with plugin usb, but pubnub did not/late received the message. can i know why? looking forward for your reply.

kmf909 commented 7 years ago

@vveljko i edit the sketch as advice and it manage to send the message to pubnub but not instantly.

update: i upload the sketch again i publish publishing error again. seems like i have 2 issue. first is publishing error and second is delay message send to pubnub. looks like not logic when both happen n the same sketch but thats what currently happen.

vveljko commented 7 years ago

Please check the latest version (2.1.0) that has improved support for HTTP status code handling. The only publish error that we reproduced was a HTTP status code error, which turned out to be "Quota exceeded". Please look at the updated Wifi101 sketch example, to see how to check the HTTP status code yourself (if you care) and print out the HTTP response body, which contains the error description.

As for the delay, it probably has something to do with your Internet connectivity/network setup. We didn't notice any significant delay in our testing. You can try to change the origin, like:

PubNub.begin(pubkey, subkey, "ps.pndsn.com");

as we have seen problems with the default pubsub.pubnub.com address sometimes on some DNS servers "in the wild".

vveljko commented 7 years ago

@kmf909 @wellard Please let us know if you have any more concerns.

Also, for more general support matters, please contact Pubnub support at support@pubnub.com