Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ESP8266 + SHT25 Sensor + ESP8266 + Arduino IDE

Status
Not open for further replies.

zoro83

Newbie level 5
Joined
Mar 29, 2018
Messages
9
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
83
Hi, I am sending the Temperature sensor data to google spreadsheet via esp8266.
The humidity readings in the serial monitor are showing fine but in the spreadsheet, it is appearing zero continuously,

I have checked both the code mentioned but not able find out the cause anywhere any suggestions on this will be great help.

Code:
#include [COLOR="#000000"]<[/COLOR]ESP8266WiFi.h>
#include [COLOR="#000000"]<[/COLOR]WiFiClientSecure.h>
#include [COLOR="#000000"]<[/COLOR]Wire.h>
String readString;
unsigned long Timer = 0;
unsigned long Interval = 5000;

#define Addr 0x40
const char* ssid = "DcubeAirtel";
const char* password = "D@Airtel190";
const char* host = "script.google.com";
const int httpsPort = 443;
float Ctemp,Ftemp,humid;
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
// SHA1 fingerprint of the certificate, don't care with your GAS service
const char* fingerprint = "fd 85 80 08 94 28 7b 0e 2f 13 06 09 d7 fd f0 23 40 7c e4 34";
String SCRIPT_ID = "AKfycbyj1wW2B_a0iazJVj43-FHZCScxZX4MMpSHdkHIgMYma-11weQE";   // Replace by your Gscript service id 
void setup() 
{ 
  // Initialise I2C communication as MASTER
  Wire.begin(2,14);
  Serial.begin(115200);
  Serial.println();
  Serial.print("connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  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());
 }

void loop() 
{
 delay(300);
 Timer = millis();
 while(millis()- Timer<=Interval)
 {
  temptask();
  delay(500);
 }
  sendData();
//  while (Serial.available()) {
//    char c = Serial.read();  //gets one byte from serial buffer
//    readString += c; //makes the string readString
//    delay(2);  //slow looping to allow buffer to fill with next character
//  }
//
//  if (readString.length() >0) {
//    Serial.println(readString);  //so you can see the captured string 
//    int n = readString.toInt();  //convert readString into a number
//
//    // auto select appropriate value, copied from someone elses code.
//    sendData(analogRead(A0),n);
//    readString=""; //empty for next input
//  } 
}

// Function for Send data into Google Spreadsheet
void sendData()
{
  
  Serial.print("connecting to ");
  Serial.println(host);
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }

  if (client.verify(fingerprint, host)) {
  Serial.println("certificate matches");
  } 
  else {
  Serial.println("certificate doesn't match");
  }
  String tempC =  String(Ctemp, 1); 
  String tempF =  String(Ftemp, 1); 
  String humiD =  String(humid, 1); 
  String url = "/macros/s/" + SCRIPT_ID + "/exec?tempC=" + tempC + "&tempF=" + tempF + "&humiD=" + humiD;
  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");
  while (client.connected()) {
  String line = client.readStringUntil('\n');
  if (line == "\r") {
    Serial.println("headers received");
    break;
  }
  }
  String line = client.readStringUntil('\n');
  if (line.startsWith("{\"state\":\"success\"")) {
  Serial.println("esp8266/Arduino CI successfull!");
  } else {
  Serial.println("esp8266/Arduino CI has failed");
  }
  Serial.println("reply was:");
  Serial.println("==========");
  Serial.println(line);
  Serial.println("==========");
  Serial.println("closing connection");
}
void temptask(){
  
unsigned int data[2];
  // Start I2C transmission
  Wire.beginTransmission(Addr);
  // Send humidity measurement command, NO HOLD master
  Wire.write(0xF5);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(500);

  // Request 2 bytes of data
  Wire.requestFrom(Addr, 2);

  // Read 2 bytes of data
  // humidity msb, humidity lsb
  if(Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();

    // Convert the data
    float humidity = (((data[0] * 256.0 + data[1]) * 125.0) / 65536.0) - 6;

    // Output data to Serial Monitor
    Serial.print("Relative Humidity :");
    Serial.print(humidity);
    Serial.println(" %RH");
    humidity = humid;
  }

  // Start I2C transmission
  Wire.beginTransmission(Addr);
  // Send temperature measurement command, NO HOLD master
  Wire.write(0xF3);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(500);

  // Request 2 bytes of data
  Wire.requestFrom(Addr, 2);

  // Read 2 bytes of data
  // temp msb, temp lsb
  if(Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();

    // Convert the data
    float cTemp = (((data[0] * 256.0 + data[1]) * 175.72) / 65536.0) - 46.85;
    float fTemp = (cTemp * 1.8) + 32;

    // Output data to Serial Monitor
    Serial.print("Temperature in Celsius :");
    Serial.print(cTemp);
    Serial.println(" C");
    Serial.print("Temperature in Fahrenheit :");
    Serial.print(fTemp);
    Serial.println(" F");
  
  Ctemp = cTemp;
  Ftemp = fTemp;
  }
  delay(300);  

}
 
Last edited by a moderator:

I am sending the Temperature sensor data to google spreadsheet via esp8266

You might be aware that adding data to an existing spreadsheet in Google Docs requires creating or using an account for this, as well as configuring the fields to fill out. Another thing is that there is no reference in your code about the general format used to upload the data values, namely:

Code:
https://spreadsheets.google.com/formResponse?formkey=YOUR_FORM_KEY & ifq & YOUR_ENTRY=VALUE_TO_STORE & submit = Submit

So review what you have done so far, and if possible simulate the data upload manually ( ie type the URL directly into the address bar of the browser ) and check if it performs update of values.
 

hi, I am using mentioned below script code

Code:
function doGet(e) { 
  Logger.log( JSON.stringify(e) );  // view parameters
  var result = 'Ok'; // assume success
  if (e.parameter == 'undefined') 
   {
    result = 'No Parameters';
   }
  else {
    var sheet_id = '1a9wJ1rC7qJ6FFCl18MYoUHZe4TAY-nwmik3z7RwcJeg';       // Spreadsheet ID
    var sheet = SpreadsheetApp.openById(sheet_id).getActiveSheet();
    var newRow = sheet.getLastRow() + 1;                        
    var rowData = [];
    rowData[0] = new Date();                                            // Timestamp in column A
    for (var param in e.parameter) {
      Logger.log('In for loop, param=' + param);
      var value = stripQuotes(e.parameter[param]);
      Logger.log(param + ':' + e.parameter[param]);
      switch (param) {
        case 'tempC': //Parameter
          rowData[1] = value; //Value in column B
          result = 'Written on column B';
          break;
        case 'tempF': //Parameter
          rowData[2] = value; //Value in column B
          result = 'Written on column C';
          break;
        case 'humiD': //Parameter
          rowData[3] = value; //Value in column C
          result += ' ,Written on column D';
          break;  
        default:
         result = "unsupported parameter";
      }
    }
    Logger.log(JSON.stringify(rowData));
    // Write new row below
    var newRange = sheet.getRange(newRow, 1, 1, rowData.length);
    newRange.setValues([rowData]);
  }
  // Return result of operation
  return ContentService.createTextOutput(result);
}
/**
* Remove leading and trailing single or double quotes
*/
function stripQuotes( value ) {
  return value.replace(/^["']|['"]$/g, "");
}
//-----------------------------------------------
// End of file
//----------------------------------------------

my main issue is that in Humidity cell getting values of 0.0

even in serial monitoring result while posting the data of humidity is not correct instead of sensor data please suggest as per mentioned result

Code:
WiFi connected
IP address: 
192.168.1.10
connecting to script.google.com
certificate doesn't match
Relative Humidity :55.47Temperature in Celsius :26.03 C
Temperature in Fahrenheit :78.85 F
Relative Humidity :55.47Temperature in Celsius :26.03 C
Temperature in Fahrenheit :78.85 F
Relative Humidity :55.47Temperature in Celsius :26.03 C
Temperature in Fahrenheit :78.85 F
requesting URL: /macros/s/AKfycbyj1wW2B_a0iazJVj43-FHZCScxZX4MMpSHdkHIgMYma-11weQE/exec?tempC=26.0&tempF=78.8&humid=0.00
request sent
headers received
esp8266/Arduino CI has failed
reply was:
==========
<HTML>
==========
closing connection


not able to understand the issue here
 

hi, I am using mentioned below script code

Where? There is no reference in your code for any instruction calling the function doGet() at the above script. Seems like you did not read what was replied above, did you try to upload data with browser instead of from within firmware ?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top