:This is the project I based it on
https://create.arduino.cc/projecthub/detox/send-mkr1000-data-to-google-sheets-1175ca
here is the original code:
//-----------------------------------------------
//This sketch is combined from Adafruit DHT sensor and tdicola for dht.h library
// https://learn.adafruit.com/dht/overview
// https://gist.github.com/teos0009/acad7d1e54b97f4b2a88
//other Authors Arduino and associated Google Script:
//Aditya Riska Putra
//Ahmed Reza Rafsanzani
//Ryan Eko Saputro
//See Also:
//http://jarkomdityaz.appspot.com/
//
//ELINS UGM
//
//Modified for Hackster.io project for the MKR1000
//by Stephen Borsay(Portland, OR, USA)
//Since Arduino can't https, we need to use Pushingbox API (uses http)to run
//the Google Script (uses https). Alternatly use Ivan's SecureWifi encryption
#include <WiFi101.h>
#include "DHT.h"
#define DHTPIN 5 // what pin we're connected to, pin1 is 5th pin from end
// Uncomment whatever DHT sensor type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21
//#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN,DHTTYPE);
const char WEBSITE[] = "api.pushingbox.com"; //pushingbox API server
const String devid = "YOUR_DEVICEID"; //device ID on Pushingbox for our Scenario
const char* MY_SSID = "YOUR SSID";
const char* MY_PWD = "YOUR WiFi PASSWORD";
int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(MY_SSID);
//Connect to WPA/WPA2 network.Change this line if using open/WEP network
status = WiFi.begin(MY_SSID, MY_PWD);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
}
void loop() {
// Wait between measurements.
delay(10000);
//prefer to use float, but package size or float conversion isnt working
//will revise in future with a string fuction or float conversion function
int humidityData = dht.readHumidity();
// Read temperature as Celsius (the default)
int celData = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
int fehrData = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(humidityData) || isnan(celData) || isnan(fehrData))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
int hifData = dht.computeHeatIndex(fehrData, humidityData);
// Compute heat index in Celsius (isFahreheit = false)
int hicData = dht.computeHeatIndex(celData, humidityData, false);
Serial.print("Humidity: ");
Serial.print(humidityData);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(celData);
Serial.print(" *C ");
Serial.print(fehrData);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hicData);
Serial.print(" *C ");
Serial.print(hifData);
Serial.println(" *F\n");
Serial.println("\nSending Data to Server...");
// if you get a connection, report back via serial:
WiFiClient client; //Instantiate WiFi object, can scope from here or Globally
//API service using WiFi Client through PushingBox then relayed to Google
if (client.connect(WEBSITE, 80))
{
client.print("GET /pushingbox?devid=" + devid
+ "&humidityData=" + (String) humidityData
+ "&celData=" + (String) celData
+ "&fehrData=" + (String) fehrData
+ "&hicData=" + (String) hicData
+ "&hifData=" + (String) hifData
);
// HTTP 1.1 provides a persistent connection, allowing batched requests
// or pipelined to an output buffer
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(WEBSITE);
client.println("User-Agent: MKR1000/1.0");
//for MKR1000, unlike esp8266, do not close connection
client.println();
Serial.println("\nData Sent");
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
I will thank you again for your willingness to help me.
My project is a system for generating energy from the sun and the wind.
That's why I have wind sensors and LEDs that are used like solar radiation sensors.
I omitted the parts of the sensor in the original plan because I don't use such a sensor.
In my project I will use the data from my sensors but right now just to check what doesn't work for me, I took the original program and put fixed values for the variables of the sensors.
The situation is quite strange because the project already worked for me with all my sensors and I even did tests for a long time and the program sent data without stopping.
And simply because I'm very busy at work so I took a little break and when I came back to work on it it didn't work well.
I didn't change the network or the program, so I don't understand what could go wrong.
The output I get in my tests varies from time to time - sometimes it sends twice and then stops, sometimes it sends once and stops, sometimes it doesn't send at all
: For example I just did a test right now and the information was sent 10 times and then stopped
14:33:37.807 -> Attempting to connect to SSID: Assaflrr
14:33:49.832 -> Connected to wifi
14:33:49.879 -> SSID: Assaflrr
14:33:49.879 -> IP Address: 10.0.0.20
14:33:49.925 -> signal strength (RSSI):-57 dBm
14:33:59.916 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:33:59.962 ->
14:33:59.962 ->
14:33:59.962 -> Sending Data to Server...
14:34:00.055 ->
14:34:00.055 -> Data Sent
14:34:10.058 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:34:10.104 ->
14:34:10.151 ->
14:34:10.151 -> Sending Data to Server...
14:34:10.197 ->
14:34:10.197 -> Data Sent
14:34:20.211 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:34:20.258 ->
14:34:20.258 ->
14:34:20.258 -> Sending Data to Server...
14:34:20.304 ->
14:34:20.304 -> Data Sent
14:34:30.352 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:34:30.399 ->
14:34:30.399 ->
14:34:30.399 -> Sending Data to Server...
14:34:30.445 ->
14:34:30.445 -> Data Sent
14:34:40.458 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:34:40.550 ->
14:34:40.550 ->
14:34:40.550 -> Sending Data to Server...
14:34:40.689 ->
14:34:40.689 -> Data Sent
14:34:50.707 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:34:50.821 ->
14:34:50.821 ->
14:34:50.821 -> Sending Data to Server...
14:34:50.821 ->
14:34:50.821 -> Data Sent
14:35:00.872 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:35:00.919 ->
14:35:00.919 ->
14:35:00.919 -> Sending Data to Server...
14:35:00.960 ->
14:35:00.960 -> Data Sent
14:35:10.980 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:35:11.073 ->
14:35:11.073 ->
14:35:11.073 -> Sending Data to Server...
14:35:11.120 ->
14:35:11.120 -> Data Sent
14:35:21.119 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:35:21.211 ->
14:35:21.211 ->
14:35:21.211 -> Sending Data to Server...
14:35:21.257 ->
14:35:21.257 -> Data Sent
14:35:31.262 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:35:31.309 ->
14:35:31.309 ->
14:35:31.355 -> Sending Data to Server...
14:35:31.401 ->
14:35:31.401 -> Data Sent
14:35:41.381 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:35:41.475 ->
14:35:41.475 ->
14:35:41.475 -> Sending Data to Server...
14:36:01.476 -> Humidity: 1 % Temperature: 2 *C 3 *F Heat index: 5 *C 4 *F
14:36:01.523 ->
14:36:01.523 ->
14:36:01.523 -> Sending Data to Server...
I will try to go back to the original code as you said and change each time a little