The use of the ESP8266 in the world of IoT

User avatar
By tytower
#24486
jeny wrote:Reply: just program it using the Arduino IDE.

In the wiki on this forum(scroll up) there are examples to send to Various similar sites and I am sure it would not take much to send the same to PubNub. Publish it here when done and I'll put it in the wiki if you like or put it in projects maybe.
User avatar
By jeny
#24614
tytower wrote:
jeny wrote:Reply: just program it using the Arduino IDE.

In the wiki on this forum(scroll up) there are examples to send to Various similar sites and I am sure it would not take much to send the same to PubNub. Publish it here when done and I'll put it in the wiki if you like or put it in projects maybe.



I have not found such thing, i was looking to use pubnub Arduino library with ESP8266 on Arduino IDE development environment.
I am novice , Need help.
User avatar
By jeny
#24633
Code: Select all#include <ESP8266WiFi.h>
 
const char* ssid     = "hhjjj";
const char* password = "qwqweer";
 
const char* host = "http://pubsub.pubnub.com";
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  // We start by connecting to a WiFi network
 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
 
int value = 0;
 
void loop() {
  delay(5000);
  ++value;
 
  Serial.print("connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
 
  // We now create a URI for the request
  String url = "/publish/demo/demo/0/puravida/0/%22Hello%20World%22";
 
  Serial.print("Requesting URL: ");
  Serial.println(url);
 
  // This will send the request to the serveg
  client.print(String("GET ") + url  + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(10);
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  Serial.println();
  Serial.println("closing connection");
}




This is my code to test publish on pubnub demo channel, but showing bad request, failed.

Anybody can help!