Iva Jerabkova in MATLAB Answers
上次活动时间: 2024-1-18

I am making a sample project from Arduino Project Hub - Plant Communicator On TS I receive data only 2 times after I upload the sketch. I want to upload data every minute, the first two minutes are successful, after that my Serial monitor shows "message sent to cloud" but nothing new shows up on TS. I also tried with another sketch that just generates numbers and uploads them on TS to make sure that there is nothing wrong with the sensors that I use in this project. With the sketch that generates random numbers and sends them to TS, I get the same outcome: data is uploaded first and second time, after that nothing. (Both sketches compiled without errors. Instead of using WiFi I tried to make a hotspot from my phone - doesn't help either.) Thanks for any help! #include "arduino_secrets.h" #include <WiFi101.h> #include<WiFiSSLClient.h> #include <RTCZero.h> #include "ThingSpeak.h" const char* ssid = SECRET_SSID; // your network SSID (name) const char* password = SECRET_PSWD; // your network password WiFiClient ThingSpeakClient; unsigned long myChannelNumber = 10; const char * myWriteAPIKey = SECRET_WRITE_API; RTCZero rtc; // create RTC object /* Change these values to set the current initial time */ const byte seconds = 0; const byte minutes = 28; const byte hours = 17; /* Change these values to set the current initial date */ const byte day = 4; const byte month = 12; const byte year = 17; int lightPin = A0; //the analog pin the light sensor is connected to int tempPin = A1; //the analog pin the TMP36's Vout (sense) pin is connected to int moisturePin= A2; // Set this threeshold accordingly to the resistance you used // The easiest way to calibrate this value is to test the sensor in both dry and wet earth int threeshold= 800; bool alert_already_sent=false; bool email_already_sent=true; bool already_sent_to_cloud=true; void setup() { Serial.begin(9600); while(!Serial); delay(2000); Serial.print("Connecting Wifi: "); Serial.println(ssid); while (WiFi.begin(ssid, password) != WL_CONNECTED) { Serial.print("."); delay(1500); } Serial.println(""); Serial.println("WiFi connected"); rtc.begin(); // initialize RTC 24H format rtc.setTime(hours, minutes, seconds); rtc.setDate(day, month, year); rtc.setAlarmTime(17, 30, 0); // Set the time for the Arduino to send the email ThingSpeak.begin(ThingSpeakClient); rtc.setAlarmTime(0, 0, 0); //in this way the request is sent every minute at 0 seconds rtc.enableAlarm(rtc.MATCH_SS); rtc.attachInterrupt(thingspeak_alarm); } void loop() { if(!already_sent_to_cloud){ ThingSpeak.setField(1,get_light()); ThingSpeak.setField(2,get_temperature()); ThingSpeak.setField(3,get_average_moisture()); ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); delay(1500); already_sent_to_cloud=true; delay(1500); Serial.println("message sent to cloud"); delay(1500); } } float get_temperature(){ int reading = analogRead(tempPin); float voltage = reading * 3.3; voltage /= 1024.0; // Print tempeature in Celsius float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset // Convert to Fahrenheit float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; return temperatureC; } int get_average_moisture(){ // make an average of 10 values to be more accurate int tempValue=0; // variable to temporarly store moisture value for(int a=0; a<10; a++){ tempValue+=analogRead(moisturePin); delay(1000); } return tempValue/10; } int get_light(){ int light_value=analogRead(A0); return light_value; } void thingspeak_alarm(){ already_sent_to_cloud=false; }
Björn Skatt in File Exchange
上次活动时间: 2015-8-5

Really simple IoT writer tool - adding data bursts, named fields and efficency option

关于 ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.