Data stream to favoriot using ESP 8266 rev 2.0

Discussion on how to get started with various type of IoT projects

Data stream to favoriot using ESP 8266 rev 2.0

Postby dimasze » Tue Oct 24, 2017 9:45 pm

Hi,

I have arduino uno board combine with ESP wifi shield rev 2.0
I have a problem to do data stream from the arduino sensor to Favoriot.

I try to use the code from favoriot tutorial: https://platform.favoriot.com/tutorial/?java#arduino

However, I realize that the code for WiFi is using common Wifi library which is not working with the ESP.

Then, I try to learn from example HTTPS client. However, I can only connect to api.github.com server.

Anybody can help? This is the example code of HTTPS client

/*
* HTTP over TLS (HTTPS) example sketch
*
* This example demonstrates how to use
* secure_connect function to access HTTPS API.
* We fetch and display the status of
* esp8266/Arduino project continuous integration
* build.
*
* Created by Ivan Grokhotkov, 2015.
* This example is in public domain.
*
* Modified by Ng Beng Chet, 2016
*/

#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <SoftwareSerial.h>

const char* ssid = "~~~~~";
const char* pass = "~~~~~~~";

const char* host = "api.favoriot.com";
const int httpsPort = 231;

void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
if(!wifi.begin(2, 3))
Serial.println(F("Error talking to shield"));
Serial.println(F("Start wifi connection"));
if(!wifi.connectAP(ssid, pass))
Serial.println(F("Error connecting to WiFi"));
Serial.print(F("Connected to: "));Serial.println(wifi.SSID());
Serial.print(F("IP address: "));Serial.println(wifi.localIP());

ESP8266Client client;
Serial.print("Connecting to ");
Serial.println(host);
if (!client.secure_connect(host, httpsPort))
{
Serial.println(F("Failed to connect to server."));
client.stop();
return;
}

String url = "/repos/esp8266/Arduino/commits/master/status";
Serial.print("requesting URL: ");
Serial.println(url);

client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");

Serial.println("request sent");
//set 5 seconds timeout for response from server
int i=5000;
while (client.available()<=0&&i--)
{
delay(1);
if(i==1) {
Serial.println(F("Timeout"));
client.stop();
return;
}
}

if(client.available())
{
if (client.find("\r\n\r\n"))
Serial.println(F("headers received"));

String line = client.readStringUntil('\n');
if (line.startsWith("{\"state\":\"success\""))
Serial.println(F("esp8266/Arduino CI successfull!"));
else
Serial.println(F("esp8266/Arduino CI has failed"));

Serial.println(F("reply was:"));
Serial.println(F("=========="));
Serial.println(line);
Serial.println(F("=========="));
Serial.println(F("closing connection"));

//flush the rest of received data
while(client.available()>0)
client.flush();
}

client.stop();
}

void loop() {
}
dimasze
Fledgling
 
Posts: 1
Joined: Tue Oct 24, 2017 9:38 pm

Re: Data stream to favoriot using ESP 8266 rev 2.0

Postby bengchet » Tue Nov 07, 2017 10:34 am

Hi,

For your case, you can use http only to communicate with favoriot.

...
const char* host = "api.favoriot.com"; <-- http setup
const int httpPort = 80;
...
...
if (!client.connect(host, httpsPort)){ <-- change secure_connect to connect
...

Thanks.

Note: Is favoriot httpsPort value 231? http or httpsPort cannot be random number, you will need to find from document. With correct ports only you can connect to server.
bengchet
Moderator
 
Posts: 235
Joined: Tue Aug 25, 2015 8:29 am

Re: Data stream to favoriot using ESP 8266 rev 2.0

Postby bengchet » Thu Nov 30, 2017 1:58 pm

Hi,

For those who are using Favoriot platform with Cytron WiFi Shield, here are couple of examples and references you can look at.

1) Youtube - COMPLETE Tutorial Cytron Uno with Favoriot Platform

2) Complete step by step tutorial document
bengchet
Moderator
 
Posts: 235
Joined: Tue Aug 25, 2015 8:29 am


Return to Getting Started - IoT

Who is online

Users browsing this forum: No registered users and 3 guests

cron