Shashank in MATLAB Answers
上次活动时间: 2024-8-7

Hi team I am Shashank Verma, I am using arduino r4 wifi to send data on thing speak. I am uploading real time data of temp, humidity, Gas conc, and AQI catagory. I am using Thingspeak free account and only sending data in every 2 min. but the transmission of data stops after 7-8 data upload. please help me in this i am builing this project in public intrest. the public channel url is " https://thingspeak.com/channels/2606075" Uploads starts again as soon as i restart arduino. the arduino code i am using is as follows "#include <DHT.h> #include <WiFi.h> #include <ArduinoHttpClient.h> #include "ArduinoGraphics.h" #include "Arduino_LED_Matrix.h" // Define the pin and type for the DHT sensor #define DHTPIN 2 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor // Initialize the LED matrix ArduinoLEDMatrix matrix; // Replace with your network credentials const char* ssid = "BSNL123"; const char* password = "yyyyyyyy"; const char* api_key = "xxxxxxxxxxxxxxxx"; const char* thingspeak_server = "api.thingspeak.com"; const int analogPin = A0; const float slope = 0.1; const float intercept = 0.5; // Initialize the WiFi server on port 80 WiFiServer wifiServer(80); // Timing variables for various updates unsigned long lastMatrixUpdate = 0; const unsigned long matrixUpdateInterval = 25000; // 25 seconds unsigned long lastSerialUpdate = 0; const unsigned long serialUpdateInterval = 55000; // 55 seconds unsigned long lastThingSpeakUpdate = 0; const unsigned long thingSpeakUpdateInterval = 60000; // 1 minute unsigned long lastWebDataSent = 0; const unsigned long webDataUpdateInterval = 10000; // 10 seconds to handle page refresh // Function to determine AQI category and numeric value void getAQICategory(float concentration, String &category, int &numericValue) { if (concentration <= 50) { category = "Good"; numericValue = 1; } else if (concentration <= 100) { category = "Satisfactory"; numericValue = 2; } else if (concentration <= 200) { category = "Moderate"; numericValue = 3; } else if (concentration <= 300) { category = "Poor"; numericValue = 4; } else if (concentration <= 400) { category = "Very Poor"; numericValue = 5; } else { category = "Severe"; numericValue = 6; } } void connectToWiFi() { WiFi.begin(ssid, password); Serial.print("Connecting to Wi-Fi"); int attempts = 0; while (WiFi.status() != WL_CONNECTED && attempts < 20) { delay(500); Serial.print("."); attempts++; } if (WiFi.status() == WL_CONNECTED) { Serial.println(); Serial.println("Connected to Wi-Fi"); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); } else { Serial.println(); Serial.println("Failed to connect to Wi-Fi"); } } void reconnectToThingSpeak() { Serial.println("Reconnecting to ThingSpeak..."); delay(10000); // Wait before attempting to reconnect } void setup() { Serial.begin(115200); dht.begin(); matrix.begin(); matrix.beginDraw(); matrix.stroke(0xFFFFFFFF); const char text[] = "Temp & Humidity"; matrix.textFont(Font_4x6); matrix.beginText(0, 1, 0xFFFFFF); matrix.println(text); matrix.endText(); matrix.endDraw(); delay(2000); connectToWiFi(); // Start the server wifiServer.begin(); } void loop() { unsigned long currentMillis = millis(); if (WiFi.status() != WL_CONNECTED) { connectToWiFi(); } // Read temperature and humidity from the DHT22 sensor float temperature = dht.readTemperature(); // in Celsius float humidity = dht.readHumidity(); // in percentage // Check if the reading is valid if (isnan(temperature) || isnan(humidity)) { Serial.println("Failed to read from DHT sensor!"); return; } // Convert temperature to Fahrenheit float ftemp = temperature; // Read analog value from MQ135 int sensorValue = analogRead(analogPin); float gasConcentration = (slope * sensorValue) + intercept; // Convert to gas concentration String aqiCategory; int aqiCategoryNumeric; getAQICategory(gasConcentration, aqiCategory, aqiCategoryNumeric); // Get AQI category and numeric value // Display data on the LED matrix if (currentMillis - lastMatrixUpdate >= matrixUpdateInterval) { matrix.beginDraw(); matrix.clear(); matrix.stroke(0xFFFFFFFF); matrix.textScrollSpeed(90); matrix.textFont(Font_5x7); matrix.beginText(0, 1, 0xFFFFFF); matrix.println("Temp: " + String(ftemp, 1) + " C"); matrix.endText(SCROLL_LEFT); delay(2000); matrix.clear(); matrix.beginText(0, 1, 0xFFFFFF); matrix.println("Hum: " + String(humidity, 1) + " %"); matrix.endText(SCROLL_LEFT); delay(2000); matrix.clear(); matrix.beginText(0, 1, 0xFFFFFF); matrix.println("AQI: " + aqiCategory); matrix.endText(SCROLL_LEFT); delay(2000); matrix.endDraw(); lastMatrixUpdate = currentMillis; } // Display data on the serial monitor if (currentMillis - lastSerialUpdate >= serialUpdateInterval) { Serial.print("Temperature: "); Serial.print(ftemp); Serial.println(" C"); Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %"); Serial.print("MQ135 Analog Value: "); Serial.println(sensorValue); Serial.print("Gas Concentration (ppm): "); Serial.println(gasConcentration); Serial.print("AQI Category: "); Serial.println(aqiCategory); lastSerialUpdate = currentMillis; } // Handle Wi-Fi client connections and send data to the local LAN WiFiClient client = wifiServer.available(); if (client) { Serial.println("Client connected"); // Read the client's request String request = client.readStringUntil('\r'); client.flush(); // Check if it's time to update the web data if (currentMillis - lastWebDataSent >= webDataUpdateInterval) { // Send the HTTP response client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"); client.print("<!DOCTYPE HTML><html><head><title>Air Quality Monitor</title></head><body>"); client.print("<h1>Temperature and Humidity</h1>"); client.print("<p>Temperature: "); client.print(ftemp); client.print(" &deg;C</p>"); client.print("<p>Humidity: "); client.print(humidity); client.print(" %</p>"); client.print("<p>AQI: "); client.print(aqiCategory); client.print("</p>"); client.print("<p>Gas Concentration: "); client.print(gasConcentration); client.print(" ppm</p>"); client.print("</body></html>"); lastWebDataSent = currentMillis; // Update the time of the last data sent Serial.println("Data sent to client"); } else { // Inform the client that the data has not changed client.print("HTTP/1.1 304 Not Modified\r\nContent-Type: text/html\r\n\r\n"); client.print("<!DOCTYPE HTML><html><head><title>Air Quality Monitor</title></head><body>"); client.print("<h1>Temperature and Humidity</h1>"); client.print("<p>Data not updated. Please refresh the page to get new data.</p>"); client.print("</body></html>"); } delay(1000); client.stop(); Serial.println("Client disconnected"); } // Send data to ThingSpeak if (currentMillis - lastThingSpeakUpdate >= thingSpeakUpdateInterval) { bool success = false; int retryCount = 0; const int maxRetries = 3; while (retryCount < maxRetries && !success) { if (WiFi.status() == WL_CONNECTED) { WiFiClient wifiClient; HttpClient httpClient = HttpClient(wifiClient, thingspeak_server, 80); httpClient.setTimeout(20000); // Set a timeout of 20 seconds String url = "/update?api_key=" + String(api_key) + "&field1=" + String(temperature) + "&field2=" + String(humidity) + "&field3=" + String(gasConcentration) + "&field4=" + String(aqiCategoryNumeric); // Send AQI category as numeric httpClient.get(url); int statusCode = httpClient.responseStatusCode(); String response = httpClient.responseBody(); if (statusCode == 200) { Serial.println("Data sent to ThingSpeak"); success = true; } else { Serial.print("Error sending data to ThingSpeak. Status code: "); Serial.println(statusCode); Serial.println("Response: "); Serial.println(response); retryCount++; delay(5000); // Wait before retrying } } else { reconnectToThingSpeak(); } } if (!success) { Serial.println("Failed to send data after multiple attempts."); } lastThingSpeakUpdate = currentMillis; } }
Mukhtar Hussain in MATLAB Answers
上次活动时间: 2024-4-25

I want to collect the AD8232 ECG sensor data through Arduino and ECG sensor AD8232 then, send that collected ECG data to IOT website ThingSpeak . Can somebody provide me with a proper Arduino code for sending the ECG sensor data to ThingSpeak website !
titus in Discussions
上次活动时间: 2023-12-6

Am running multiple sensors in the field producing strings of data then sending them to a node. The node is an Arduino Uno on which SIM 800 is attached for internet connectivity. After computation, the result is several strings that i want to display to things speak. The code i have so far can only upload numerical data. Am in need of help to display these strings in Thingsspeak.Help me. How to display Strings in Thingspeak using SIM800 and Arduino Uno You can write string data to ThingSpeak just as you write numrical data. The automatic field plots wont show it, so you can write that string data to the status field, and enable the status display in your channel settings. Or create a custom MATLAB visualization to show the text read from any field. To create the visualization, you can use thingSpeakRead, then figure, then the text function, or various other methods. sim 800 sim800 arduino uno
emmanuel jallas in MATLAB Answers
上次活动时间: 2022-6-2

Hello to everyone. I will be very gratefull for support and knowledge sharing with AT commands and troubleshooting knowledge with hardware setup and software. Hardware context : Arduino Uno, SIM800F GSM shield , USB connection and power, Rx -Tx GSM connection strapped on Software Serial Concerning SIM card. Inserted on a mobile phone, can send and receive SMS and phone communications. Data plan available. Software context : I'm using Serial monitor to send AT commands and receive answers. Aim : to follow manually the proper AT sequence to send one piece of data to one field of one channel. Code : [code] // Sending AT commands via Serial Monitor interface #include<SoftwareSerial.h> SoftwareSerial mySerial(2,3); // setting up GSM serial communication void setup() { digitalWrite(8, HIGH); // Switching on GSM shield delay(1100); digitalWrite(8,LOW); mySerial.begin(9600); Serial.begin(9600); Serial.println("Type AT command :"); } void loop() { if (mySerial.available()) Serial.write(mySerial.read()); if (Serial.available()) mySerial.write(Serial.read()); } [/code] Setup : AT returns OK, SMS ready, CALL ready AT+CPIN? returns ready As far I understand the proper sequence of AT commands to connect device to thingspeak server and send data should be this : AT // is SIM800F ready ? good return is : OK AT+CGREG? // is SIM800F registered on GPRS provider network ? good return is : +CGREG: 0,1 (edited) AT+CGATT? // is GPRS attached or not ? good return is : +CGATT: 1 AT+CIPSHUT // resets previous IP session if any. good return is : SHUT OK AT+CIPSTATUS // Check if IP stack is intitalized. good return is : STATE: IP INITIAL AT+CIPMUX=0 // Sets single connection mode. good return is : OK AT+CSTT="APN","","" // Starts task. good return is : OK AT+CIPSTATUS // Not needed but for troubleshooting Check IP status. good return is : STATE: IP START AT+CIICR // Brings up wireless connection. good return is : OK and quick flashing led (edited) AT+CIPSTATUS // Not needed but for troubleshooting Check IP status. good return is : STATE: IP GPRSACT (edited) AT+CIFSR // Gets local IP adress. good return is : anything else than "0.0.0.0" AT+CIPSTART="TCP", "api.thingspeak....","80" // Starts connection with TCP protocol, TCP, domain name, port. good return is : CONNECT OK AT+CIPSEND // Data sending request. good return is : > > data string // Sends data to the proper field and channel >#026 // Ctrl+Z input to indicate the end of data AT+CIPSHUT // Shuts down UDP context. good return is : SHUT OK At this time : AT+CGREG? is returning : +CGREG: 1,0 which states : network registration is enabled, device is not registered and searching for operator's network (edited) AT+CGATT? is returning : 0, which states GPRS is detached AT+CIICR is returning +PDP: DEACT, ERROR Question : What may prevent network registration and getting a +CGREG: 0,1 return ? (edited) How can I troubleshoot and assess actual situation ? Thank you for your insights.
Megha Patil in MATLAB Answers
上次活动时间: 2022-5-26

Can i send the three sensor data (functions are connected on each other in project) on same channel as field 1, field 2, field 3 ? how it is possible? Thank you.
Aidi Tan in Discussions
上次活动时间: 2022-2-11

#include <Keypad.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <SoftwareSerial.h> LiquidCrystal_I2C lcd(0x27, 16, 2); SoftwareSerial ESP01(2, 3); const byte ROWS = 4; // four rows const byte COLS = 3; // three columns char keys[ROWS][COLS] = { // keypad labels {'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}, {'*', '0', '#'} }; byte rowPins[ROWS] = {12, 7, 8, 10}; //connect to keypad pins 12, 7, 8, 10 byte colPins[COLS] = {11, 13, 9}; // connect to keypad pins 11, 13, 9 column pinouts Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); #define Password_Length 5 #define DEBUG true #define IP "184.106.153.149" // define pin numbers int buzzer = 5; // buzzer is connected to pin 5 int PIR = 6; // PIR is connected to pin 6 // intruder alarm password char Data[Password_Length]; char Master[Password_Length] = "1234"; byte data_count = 0, master_count = 0; bool Pass_is_good; char customKey; int val = 0; // thingspeak & WiFi String apiKey = "xxxxxxxxxxxxxxxx"; // thingspeak API key void setup() { lcd.init(); lcd.backlight(); pinMode(buzzer, OUTPUT); pinMode(PIR, INPUT); Serial.begin(9600); while (!Serial){ } Serial.println("Starting..."); ESP01.begin(9600); // Reset ESP8266, put it into mode 1 i.e. STA only, make it join hotspot / AP, // establish single connection ESP01.println(); sendData("AT+RST\r\n",2000,DEBUG); sendData("AT+CWMODE=1\r\n",2000,DEBUG); sendData("AT+CWJAP=\"AiPhone\",\"123889\"\r\n",20000,DEBUG); sendData("AT+CIPMUX=0\r\n",4000,DEBUG); // Make TCP connection String cmd = "AT+CIPSTART=\"TCP\",\""; cmd += "184.106.153.149"; // Thingspeak.com's IP address cmd += "\",80\r\n"; sendData(cmd,4000,DEBUG); // Read PIR sensor value val = digitalRead(PIR); // check if there was a state transition String val1 = String(val); if (val == HIGH) { Serial.println("Motion detected!"); delay(10); Serial.println(val1); } else { Serial.println("Asleep"); delay(10); //String val1 = String(val); Serial.println(val1); } //String val1 = String(val); //Serial.println(val1); //Prepare GET string String getStr = "GET /update?api_key="; getStr += apiKey; getStr += "&field1="; getStr += val1; getStr +="\r\n"; // Send data length & GET string ESP01.print("AT+CIPSEND="); ESP01.println (getStr.length()); Serial.print("AT+CIPSEND="); Serial.println(getStr.length()); delay(500); if(ESP01.find (">")) { Serial.print(">"); sendData(getStr, 2000, DEBUG); } //Close connection, wait a while before repeating sendData("AT+CIPCLOSE", 16000, DEBUG); // 15 seconds delay between updates } if true % code endvoid loop() { if (digitalRead(PIR) == HIGH) { lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Enter Password: "); customKey = customKeypad.getKey(); if (customKey) { Data[data_count] = customKey; lcd.setCursor(data_count, 1); lcd.print(Data[data_count]); data_count++; } if (data_count == Password_Length - 1) { lcd.clear(); if (!strcmp(Data, Master)) { lcd.print("OK"); digitalWrite(buzzer, HIGH); delay(200); digitalWrite(buzzer, LOW); delay(200); digitalWrite(buzzer, HIGH); delay(200); digitalWrite(buzzer, LOW); } else { lcd.print("Wrong Password"); digitalWrite(buzzer, HIGH); delay(1000); digitalWrite(buzzer, LOW); } lcd.clear(); clearData(); } } else { lcd.noBacklight(); // turn backlight off lcd.clear(); // clear display delay(250); } } String sendData(String command, const int timeout, boolean debug) { String response = ""; ESP01.print(command); long int time = millis(); while( (time+timeout) > millis()) { while(ESP01.available()) { // "Construct" response from ESP01 as follows // - this is to be displayed on Serial Monitor. char c = ESP01.read(); // read the next character. response+=c; } } if(debug) { Serial.print(response); } return (response); } void clearData() { while (data_count != 0) { Data[data_count--] = 0; } return; } thingspeak not reading my IR sensor.. is there something wrong with my code? Can you comment out the IR sensor parts and just send a static number to ThingSpeak for testing? Then we can tell if its the sensor or the ThingSpeak interface part. arduino uno thingspeak ir sensor

关于 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.