Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By kas
#61881 Juan,
You did an interesting exercise ;)

So, the first line in setup() is:
t0 = millis();

the last line before creating the ThingSpeak data string is
tTot = millis() - t0; // get ms since boot

I then build the data string
data = "field1="+String(oneWireVal[0],1) + "&field2="+String(oneWireVal[1],1) + "&field3="+String(tTot);

BTW, I tried MQTT for a couple of days and reverted back to HTTP
In my opinion, ThingSpeak implementation is not yet ready for prime time :|

.
User avatar
By juan3211
#61904 Hi @kas.

So your sketch doesn't consider the time of sending data to the servers, does it ?

Probably you don't need if you are only trying to reduce the global time. In my case, a comparation, I need the time with the protocol's waste of time included.

Regards

kas wrote:Juan,
You did an interesting exercise ;)

So, the first line in setup() is:
t0 = millis();

the last line before creating the ThingSpeak data string is
tTot = millis() - t0; // get ms since boot

I then build the data string
data = "field1="+String(oneWireVal[0],1) + "&field2="+String(oneWireVal[1],1) + "&field3="+String(tTot);

BTW, I tried MQTT for a couple of days and reverted back to HTTP
In my opinion, ThingSpeak implementation is not yet ready for prime time :|

.
User avatar
By GengusKahn
#61914 Hi there, for a basic approach......

Code: Select all#include "ESP8266WiFi.h"


    char ssid[] = "YourSSID";     //  your network SSID (name)
    char pass[] = "YourPASSWD";   //  your network password
    WiFiClient  client;
float pfHum   = 44.9;
float pfTemp  = 22.9;
float pfHum1  = 44.9;
float pfTemp1 = 22.9;
float pfVcC   = 3.49;
   
const char* hostts = "api.thingspeak.com";
const char* thingspeak_key = "YourWriteKey";

void setup() {
      WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
  }
}

void loop() {
 // Use WiFiClient class to create Thingspeak Post
  WiFiClient client;
  if (!client.connect(hostts, 80)) {
    return;
  }
  //Construct the post...
  String url = "/update?key=";
  url += thingspeak_key;
  url += "&field1=";
  url += pfTemp;
  url += "&field2=";
  url += pfHum;
  url += "&field3=";
  url += pfTemp1;
  url += "&field4=";
  url += pfHum1; 
  url += "&field5=";
  url += pfVcC/1000;
 
// This will send the Thingspeak Post request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + hostts + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(50);
  client.stop();
ESP.deepSleep(3600000000, WAKE_RF_DEFAULT);  // Sleep for 60 Minutes
}
User avatar
By kas
#61953
Probably you don't need if you are only trying to reduce the global time.
Right, my concern was to reduce both router connection time and 1wire 18B20 sensors acquisition

ThingSpeak MQTT implementation looks pretty much as a marketing trick as it does not share data with other MQTT clients