Main Content

Results for

my code is as below:
#include "DHT.h"
#define DHTPIN 15 // what pin we're connected to
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define THINGSPEAK_API_KEY "1P4RY69D3YMP9R5W"
#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//-----------------------------
#include <ArduinoJson.h>
StaticJsonDocument<200>JsonDocument;
SoftwareSerialmyserial(10, 11);
//-------------------------
float voltage;
unsignedintfrac;
//---------------------
#define ONE_WIRE_BUS 5
OneWireoneWire(ONE_WIRE_BUS);
DallasTemperaturesensors(&oneWire);
floatCelcius = 0;
float Fahrenheit = 0;
//==========================================================================================================
bytesensorInterrupt = 0; // 0 = digital pin 2
bytesensorPin = 2;
// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
floatcalibrationFactor = 5.5; //==========================================================we change cal factor 4.5 to 5.5 if not work chnage again(4.5)
//========== 5.5 calibration factor is working efficent then 4.5 , 7.5 ,and 6.5
volatile byte pulseCount;
floatflowRate;
unsignedintflowMilliLitres;
unsigned long totalMilliLitres, tempTotal = -1;
unsigned long oldTime;
//-------------------------------------------------------
intpH_Value;
float Voltage;
//----------------------------------------------------------------------------------------------
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myserial.begin(9600);
//--------------------------------
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0; // ============================================================
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
sensors.begin();
//------------------------------------------------
/********************GSM Communication Starts********************/
if (myserial.available())
Serial.write(myserial.read());
myserial.println("AT");
delay(1000);
myserial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
delay(1000);
ShowSerialData();
myserial.println("AT+SAPBR=3,1,\"APN\",\"www\"");//APN
delay(1000);
ShowSerialData();
myserial.println("AT+SAPBR=1,1");
delay(1000);
ShowSerialData();
myserial.println("AT+SAPBR=2,1");
delay(1000);
ShowSerialData();
//---------------------------------
}
void loop() {
// put your main code here, to run repeatedly:
inti;
for (i = 0; i< 20; i++)
{
flow_meter();
}
temperature();
turbidity();
delay(1000);
gsm();
}
voidflow_meter()
{
if ((millis() - oldTime) > 1000) // Only process counters once per second
{
// Disable the interrupt while calculating flow rate and sending the value to
// the host
detachInterrupt(sensorInterrupt);
// Because this loop may not complete in exactly 1 second intervals we calculate
// the number of milliseconds that have passed since the last execution and use
// that to scale the output. We also apply the calibrationFactor to scale the output
// based on the number of pulses per second per units of measure (litres/minute in
// this case) coming from the sensor.
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
// Note the time this processing pass was executed. Note that because we've
// disabled interrupts the millis() function won't actually be incrementing right
// at this point, but it will still return the value it was set to just before
// interrupts went away.
oldTime = millis();
// Divide the flow rate in litres/minute by 60 to determine how many litres have
// passed through the sensor in this 1 second interval, then multiply by 1000 to
// convert to millilitres.
flowMilliLitres = (flowRate / 60) * 1000;
// Add the millilitres passed in this second to the cumulative total
totalMilliLitres += flowMilliLitres;
// Print the flow rate for this second in litres / minute
/* Serial.print("Flow rate: ");
Serial.print(int(flowRate)); // Print the integer part of the variable
Serial.print("."); // Print the decimal point */
// Determine the fractional part. The 10 multiplier gives us 1 decimal place.
frac = (flowRate - int(flowRate)) * 10;
Serial.print(frac, DEC) ; // Print the fractional part of the variable
Serial.println("L/min");
/* // Print the number of litres flowed in this second
Serial.print(" Current Liquid Flowing: "); // Output separator
Serial.print(flowMilliLitres);
Serial.print("mL/Sec");
// Print the cumulative total of litres flowed since starting
Serial.print(" Output Liquid Quantity: "); // Output separator
Serial.print(totalMilliLitres);
Serial.println("mL"); */
if ( tempTotal != totalMilliLitres ) {
tempTotal = totalMilliLitres;
// displayVolumeOfWater(totalMilliLitres );
}
// Reset the pulse counter so we can start incrementing again
pulseCount = 0;
// Enable the interrupt again now that we've finished sending output
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
//=========================================================================================================================
}
voidpulseCounter()
{
// Increment the pulse counter
pulseCount++;
}
//-------------------------------------------------------------------------
void temperature()
{
sensors.requestTemperatures();
Celcius = sensors.getTempCByIndex(0);
Fahrenheit = sensors.toFahrenheit(Celcius);
Serial.print(" C ");
Serial.print(Celcius);
// Serial.print(" F ");
// Serial.println(Fahrenheit);
delay(1000);
}
//------------------------------------------------------------
void turbidity()
{
intsensorValue = analogRead(A0);
voltage = sensorValue * (5.0 / 1024.0);
// Serial.println ("Sensor Output (V):");
Serial.println (voltage);
// Serial.println();
delay(1000);
}
//------------------------------------------------------------
voidgsm()
{
myserial.println("AT+HTTPINIT");
delay(1000);
ShowSerialData();
myserial.println("AT+HTTPPARA=\"CID\",1");
delay(1000);
ShowSerialData();
StaticJsonDocument<200>JsonDocument;
JsonObject& object = JsonDocument.createObject();
object.set("TE", Celcius);
object.set("TU", voltage);
object.set("WF", frac);
delay(1000);
object.printTo(Serial);
Serial.println(" ");
String sendtoserver;
object.prettyPrintTo(sendtoserver);
delay(1000);
//myserial.println("AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=\""); //Server address
myserial.println("AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=\""); //Server address
delay(1000);
ShowSerialData();
myserial.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
delay(1000);
ShowSerialData();
myserial.println("AT+HTTPDATA=" + String(sendtoserver.length()) + ",100000");
Serial.println(sendtoserver);
delay(1000);
ShowSerialData();
myserial.println(sendtoserver);
delay(2000);
ShowSerialData;
myserial.println("AT+HTTPACTION=1");
delay(1000);
ShowSerialData();
myserial.println("AT+HTTPREAD");
delay(1000);
ShowSerialData();
myserial.println("AT+HTTPTERM");
delay(1000);
ShowSerialData;
}
voidShowSerialData()
{
while (myserial.available() != 0)
Serial.write(myserial.read());
delay(1000);
}
My following code works running Matlab 2024b for all test cases. However, 3 of 7 tests fail (#1, #4, & #5) the QWERTY Shift Encoder problem. Any ideas what I am missing?
Thanks in advance.
keyboardMap1 = {'qwertyuiop[;'; 'asdfghjkl;'; 'zxcvbnm,'};
keyboardMap2 = {'QWERTYUIOP{'; 'ASDFGHJKL:'; 'ZXCVBNM<'};
if length(s) == 0
se = s;
end
for i = 1:length(s)
if double(s(i)) >= 65 && s(i) <= 90
row = 1;
col = 1;
while ~strcmp(s(i), keyboardMap2{row}(col))
if col < length(keyboardMap2{row})
col = col + 1;
else
row = row + 1;
col = 1;
end
end
se(i) = keyboardMap2{row}(col + 1);
elseif double(s(i)) >= 97 && s(i) <= 122
row = 1;
col = 1;
while ~strcmp(s(i), keyboardMap1{row}(col))
if col < length(keyboardMap1{row})
col = col + 1;
else
row = row + 1;
col = 1;
end
end
se(i) = keyboardMap1{row}(col + 1);
else
se(i) = s(i);
end
% if ~(s(i) = 65 && s(i) <= 90) && ~(s(i) >= 97 && s(i) <= 122)
% se(i) = s(i);
% end
end
Need code to collect data of waterflow sensor using ESP 8266 and to stoe it in ThingSpeak cloud
Ciao a Tutti,qualche mese fa avevo costruito una stazione meteo con un esp32 e vari sensori.
Tutto funzionava, adesso però ho riprovato, e non funziona più. Ho provato a creare un canale nuovo con nuovo ID canale, nuovo ID Client, nuovo Utente (uguale al Client) e nuova Password. si connette (ho inserito un comando se connesso a MQTT scrivi.....) ma non publica i dati.
Non reisco a saltarne fuori, ècambiato qualche cosa?
grazie a tutti
Hello,
could it be that there is currently is a stability problem with the MQTT-Broker? I can establisth a connection successfully using the MQTTX client (web and win64 installation). I tried all possible ports an connection types. It disconnects all the time after a few seconds of establishing a connection successfully. So it was not possible to subscribe any item. I do not think the problem is in my side... By the way, protocol verision 3.1.1 ist supported, 5.0 not, am I right?
Maybe you could give me a hint,
Best regards,
Manfred
in the below code write is working fine, but read is failing ( 404 error) can you please help me reslove this.
/*
Go to thingspeak.com and create an account if you don't have one already.
After logging in, click on the "New Channel" button to create a new channel for your data. This is where your data will be stored and displayed.
Fill in the Name, Description, and other fields for your channel as desired, then click the "Save Channel" button.
Take note of the "Write API Key" located in the "API keys" tab, this is the key you will use to send data to your channel.
Replace the channelID from tab "Channel Settings" and privateKey with "Read API Keys" from "API Keys" tab.
Replace the host variable with the thingspeak server hostname "api.thingspeak.com"
Upload the sketch to your ESP32 board and make sure that the board is connected to the internet. The ESP32 should now send data to your Thingspeak channel at the intervals specified by the loop function.
Go to the channel view page on thingspeak and check the "Field1" for the new incoming data.
You can use the data visualization and analysis tools provided by Thingspeak to display and process your data in various ways.
Please note, that Thingspeak accepts only integer values.
You can later check the values at https://thingspeak.com/channels/2005329
Please note that this public channel can be accessed by anyone and it is possible that more people will write their values.
*/
#include <WiFi.h>
const char *ssid = "xxxx"; // Change this to your WiFi SSID
const char *password = "xxxxx"; // Change this to your WiFi password
const char *host = "api.thingspeak.com"; // This should not be changed
const int httpPort = 80; // This should not be changed
const String channelID = "2805914"; // Change this to your channel ID
const String writeApiKey = "xxxxxxxxxxxxxxxx"; // Change this to your Write API key
const String readApiKey = "xxxxxxxxxxxxxxxx"; // Change this to your Read API key
// The default example accepts one data filed named "field1"
// For your own server you can ofcourse create more of them.
int field1 = 20;
//int field1 = 20;
int numberOfResults = 1; // Number of results to be read
int fieldNumber = 1; // Field number which will be read out
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(100);
}
// We start by connecting to a WiFi network
Serial.println();
Serial.println("******************************************************");
Serial.print("Connecting to ");
Serial.println(ssid);
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 readResponse(NetworkClient *client) {
unsigned long timeout = millis();
while (client->available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client->stop();
return;
}
}
// Read all the lines of the reply from server and print them to Serial
while (client->available()) {
String line = client->readStringUntil('\r');
Serial.print(line);
}
Serial.printf("\nClosing connection\n\n");
}
void loop() {
NetworkClient client;
String footer = String(" HTTP/1.1\r\n") + "Host: " + String(host) + "\r\n" + "Connection: close\r\n\r\n";
// WRITE --------------------------------------------------------------------------------------------
if (!client.connect(host, httpPort)) {
return;
}
client.print("GET /update?api_key=" + writeApiKey + "&field1=" + field1 + footer);
readResponse(&client);
delay(200);
// READ --------------------------------------------------------------------------------------------
String readRequest = "GET /channels/" + channelID + "/fields/" + fieldNumber + ".json?results=" + numberOfResults + " HTTP/1.1\r\n" + "Host: " + host + "\r\n"
+ "Connection: close\r\n\r\n";
if (!client.connect(host, httpPort)) {
return;
}
client.print(readRequest);
readResponse(&client);
// -------------------------------------------------------------------------------------------------
//++field1;
delay(10000);
}
Thingspeak
Thingspeak channel shows a "watch" - "un-watch" selection box. What does this do?
Thanks
Aaron
Aaron
Last activity on 23 Dec 2024

Dear Sir,
I login my channel in a device using my user name and password (also client id & password) but when I also login using the same user name and password in another device, the first one connection was forced disconnected. I want to publish via thinkspeak mqtt by using the two devices. Please advise how I can do it. Can I use the same thinkspeak user name to login? Is it needed to have another thinkspeak user to login? In this case, please also advise. Many thanks.
Aaron
I have a device that via GPRS publish correctly, after autentication to the server mqtt3.thingspeak.com , a lot of datas like:
.{"sensorDatas":[{"flag":"COUNT","value":1},...........,{"flag":"AI1","value":25.80}]}
I configure a correct Channel with a field called AI1, but I can't fill it with that value 25.80.
I am sure that the device communicate to the server the string {"flag":"AI1","value":25.80} but nothing.
Could you tell me what I have to do? Probably I have to write some software code, may someone help me?
Are there some examples for a beginner like me?
Thank you very much
Ivan
Ivan
Last activity on 13 Dec 2024

Hello
I am trying to connect Thingspeak to ibfluxdb. Is that possible? how you do that??
I am using a micro:bit device with ESP8266 for a IOT project, but cannot connect thingspeak recently.
The conncection is unstable, I can hardly connect to thingspeak for days, somehow it works last night for 30 mins and then it fails.
The program does not change and I have included a 25 sec delayed between each data sending.
Please advice why and how to fix it. Thank you.
I am using the ELECFREAKS IOT:bit Expansion Board with micro:bit to record data, it worked normally but in this week I tested again, and discover no data is uploaded to the channel ie.no entries in channel. The code in makecode are the same as before and the wifi is work, I cannot find the reason that cause this failure.
Chuanjun
Chuanjun
Last activity on 25 Nov 2024

I am using the free option with 4 channels available. I do not have any channels listed, but when I want to create a new channel it gives me an error massage to say that I have used up my 4 channels and need to purchase units to create additional channels.
Torbjorn
Torbjorn
Last activity on 18 Nov 2024

Hello
I have 3 devices (IOT board using SIM7600 module) sending one value to Thingsspeak. Have been working just fine a couple of years. However 14/11-24 I receive http error code 406 for all 3 devices.
The http get is working just fine when testing directly in the browser (https://api.thingspeak.com/update?api_key=xxxxx&field1=33), the server return the entrie number.
However, when running the same address via SIM7600 I receive - +HTTPACTION: 0,406,0
Any tips for the 406 error code?

Hello, I am wondering why I have over 12000 messages (writes)per day to a channel which I only update all 8 fields every 20 minutes. Or are these statistic timely delayed? Since testing I might have more writes, but now with my ready weather station only every 20 minutes my data will be updated. Wetterbox Channel ID: 2391212 Access: Public Can you explain this to me? Thank you for your help. Regards, Julian

I am considering to upgrade to HOME license. Does the HOME license provides more widgets (including a text message widget), in addition to the 4 basic widgets in the FREE version?
Hi,
I don't know why really. Why is there seems a difference between daily average that calculated with .csv file that has exported directly from the channel.
and calculation with the ThingSpeak Daily Average API, there is a lot of difference at the moment.
Why does this happens, and how should I fix this issue?
Attached image file is daily average that has been retrived through the API,
And attached excel file is raw data from the channel.
Thank you.
Sundown
Sundown
Last activity on 16 Oct 2024

My Licensed avvount has expired. When I go to my expired license page, I select "Revert To Free Account", I get the following message:
Only administrators of this license are allowed to renew units on this ThingSpeak license. If you want to continue to collect data in your ThingSpeak channels, contact your license administrator.
Aren't I the license administrator? or do I need to contact someone at Thingspeak/MathWorks?
Hi, My data send to thingspeak is not received/updated for the last 6 hours on the charts and dials. All worked well till about 6 hour ago. I am using Node-red and the API Url: https://thingspeak.com
Any help please?
Greetings Gert
To solve issues around the browsers blocking 3p cookies and having different behavior across different browsers, the ThingSpeak website is now served from https://thingspeak.mathworks.com. There are no changes required from devices or users. Just log in and use the service as you always did.