Quantcast
Channel: ThingSpeak IoT Community - Forum: ThingSpeak Apps
Viewing all 223 articles
Browse latest View live

clag on Adding units to Google Gauge: ie. %, hPa, °C

$
0
0

I'd like to be able to add units to the bottom value on google gauges. I have tried:

var formatter = new google.visualization.NumberFormat({pattern: "#'%'"});

but cannot get it to work.

also:

var formatter = new google.visualization.NumberFormat(
{suffix: '%',pattern:'#'}
);
formatter.format(data,1);

 

Could anyone help me?


Vinod on Adding units to Google Gauge: ie. %, hPa, °C

$
0
0

I have this code that puts the units on a gauge. Perhaps you can modify it for your use case:

 

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>

// set your channel id here
var channel_id = MYCHANNELNUM;
// set your channel's read api key here if necessary
var api_key = 'MYCHANNELKEY';
// maximum value for the gauge
var max_gauge_value = 100;
// maximum value for the gauge
var gauge_text = '°C';

// global variables
var chart, charts, data;

// load the google gauge visualization
google.load('visualization', '1', {packages:['gauge']});
google.setOnLoadCallback(initChart);

// display the data
function displayData(point) {
data.setValue(0, 0, gauge_text);
data.setValue(0, 1, point);
chart.draw(data, options);
}

// load the data
function loadData() {
// variable for the data point
var p;

// get the data from thingspeak
$.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/feed/last.json?api_key=' + api_key, function(data) {

// get the data point
p = data.field1;

// if there is a data point display it
if (p) {
p = (Math.round((p / max_gauge_value) * 1000) / 10);
displayData(p);
}

});
}

// initialize the chart
function initChart() {

data = new google.visualization.DataTable();
data.addColumn('string', 'Label');
data.addColumn('number', 'Value');
data.addRows(1);

chart = new google.visualization.Gauge(document.getElementById('gauge_div'));
options = {min: 25, width: 240, height: 240, redFrom: 90, redTo: 100, yellowFrom:75, yellowTo: 90, minorTicks: 5};

loadData();

// load new data every 15 seconds
setInterval('loadData()', 15000);
}

</script>

bobybc on Channel Value Replacements - timestamp?

$
0
0

Hi,

i know ow to use fileds in TingHTTP, but does someone knows hot to annotate timestamp?

 

10x

Boby

Channel Value Replacements

Include channel data in your ThingHTTP request to get the last value from a channel field:

%%channel_CHANNEL_ID_field_FIELD_NUMBER%%

jaza_tom on Can't use data from thingSpeakRead to parse comma delimited values

$
0
0

Hello,

I'm finding the reference for thingSpeak extremely lacking so I have turned here in exasperation.

I am using the thingSpeakRead() function to read the most recent value from Field 1 of my private channel.  The data that this field stores is a string of comma-separated values.

I want to take this list of values, parse them, and write them to their corresponding field on a different private channel I own.

I have the following code:

data = thingSpeakRead(readChannelID,'ReadKey', readAPIKey,'NumPoints', 1, 'Fields', [1]);

dataArray = strsplit(data, ',');

 

If I try and run this code, I get the following error message in the "Output" box:

Error using strsplit
First input must be either a character vector or a string scalar.

So, obviously the data that thingSpeakRead() returned was not a string (or "character vector" as I guess MATLAB calls it...).

Not sure where to go from here.... is there a way to access this string of values stored in Field 1?Cry

Adarsh_Murthy on Can't use data from thingSpeakRead to parse comma delimited values

$
0
0

Hi, 

thingSpeakRead() by default returns data back as a numeric array. For your case, since the data on the ThingSpeak channel is a string, you should use the 'OutputFormat' names parameter to request for data back as a table:

data = thingSpeakRead(readChannelID,'ReadKey', readAPIKey,'NumPoints', 1, 'Fields', [1], 'OutputFormat', 'table');

You will then need to access the data in the table (data.<columnName>) to apply strsplit() function. Refer to the following link on how to access data in a table:

https://www.mathworks.com/help/matlab/ref/table.html

https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html

 

If this doesn't work, share the values stored in the data table and we might be able to provide additional suggestions.

 

HTH!

mandelkind on Escape Custom Replacement Keys in ThingHTTP

$
0
0

How may I escape custom replacement keys in ThingHTTP?

https://ch.mathworks.com/help/thingspeak/thinghttp-app.html#bvevu2b-5

 

I've managed to get an API request up and running and everything seems to work perfectly. At least, everything except one thing:

In my ThingHTTP body there are custom replacement key which get replaced by the passed in values:

labels=ThingHTTP,%%labels%%&title=%%title%%&description=%%description%%

 

Unfortunately, as soon as one of the replacement values contain special characters, such as & or +, things are going weird.

How may I tell ThingHTTP to escape the custom replacement keys before sending them along in a POST request?

Hans on Escape Custom Replacement Keys in ThingHTTP

$
0
0

Have you tried URL encoding ? There are websites that will do the encoding for you. Let us know if you try that. 

jaza_tom on Can't use data from thingSpeakRead to parse comma delimited values

$
0
0

Thanks for the reply!  Clearly I have a lot to learn about MATLAB...

I now have the thingSpeakRead() function returning a table.  It would appear that it thinks the column with the comma-delimited strings in it is a variable of type double

Here is my code:

%% Read Data %%
data = thingSpeakRead(readChannelID,'ReadKey', readAPIKey, 'OutputFormat', 'table');

%% Analyze Data %%
% Add code in this section to analyze data and store the result in the
% analyzedData variable.
summary(data);

disp ----------------;

testVar = data.allData(1);
disp(testVar);

disp ----------------;

whos;

.... and the output:

Variables:

Timestamps: 1×1 datetime
Values:

min 01-Nov-2016 13:56:35
median 01-Nov-2016 13:56:35
max 01-Nov-2016 13:56:35

allData: 1×1 double
Values:

min NaN
median NaN
max NaN
NaNs 1

----------------
NaN

----------------
Name Size Bytes Class Attributes

data 1x2 1198 table
metacl 1x1 8 meta.class
readAPIKey 1x16 32 char
readChannelID 1x1 8 double
testVar 1x1 8 double
writeAPIKey 1x16 32 char
writeChannelID 1x1 8 double

 

Any idea why I am getting a double instead of a string?Yell

EDIT:

Here is the first few rows of the table, with headers:

created_at entry_id field1
30-10-16 13:14 135 1477844100, 11.13,  0.78,  8.73,  2.14, 11.64,  1.27, 14.74,  3.56, 21.95,  5.41,  0.00,  0.00,  5.01,  1.22,  1.08,  0.25,
30-10-16 13:29 136 1477845000, 11.15,  0.84,  9.39,  2.33, 11.66,  1.29, 15.03,  3.69, 22.85,  5.66,  0.00,  0.00,  5.02,  1.23,  1.07,  0.26,

mandelkind on Escape Custom Replacement Keys in ThingHTTP

$
0
0

@Hans: I'm unable to add any additional encoding, since the data is passed by a 3rd party service (IFTTT) - and there is the data already urlEncoded. I suspect ThingHTTP receives the data & urlDecodes it, before sending it along.

So the only solution I can see is that ThingHTTP should ensure it can be passed without any issues. 

Adarsh_Murthy on Can't use data from thingSpeakRead to parse comma delimited values

$
0
0

Hi, 

Thanks for sharing the additional info. ThingSpeakRead at present doesn't support the case where a numeric vector is stored in a single field. We will consider this in a future update of the ThingSpeakRead function.

In the meanwhile, to access your data in a MATLAB Analysis App, you can use the following lines of code instead:

data = webread('https://api.thingspeak.com/channels/<channelID>/feeds.json?api_key=<read_Key>&results=1')
myData = data.feeds.field1;

 

The data returned from thingSpeak will be stored in the variable data as a structure. As shown in your previous post, since the value of interest is stored in field1, myData should contain the data of interest.

NOTE: you need to replace <channelID> and <read_Key> with their appropriate values. 

Let me know if this doesn't work for you.

gaz_iot on nov 7, tweetcontrol not working for me

$
0
0

worked yersteday do not today

I have a number of controls through thweetcontrol. They worked well yesterday and today there is no way to make them work. Likewise I've tried cheerliht and does not change color, watching the feed of the latter does not change from blue from yesterday at 7/11/2016 00:45:35 -0500.182657, blue, # 0000FF

IT is something  related to?

 

thanks in advance.

Hans on nov 7, tweetcontrol not working for me

$
0
0

Thanks for reporting. We are looking into the issue.

Vinod on nov 7, tweetcontrol not working for me

$
0
0

It appears that this was related to the Twitter API servers IP address changes.

@gaz_iot: Can you confirm tweetcontrols are working now?

gaz_iot on nov 7, tweetcontrol not working for me

eggfile on Auto update ThingSpeakPlot charts

$
0
0

Hi, I use two Arduinos to count certain events. Each Arduino is sending its counter every 20sec to its Channel, i.e. I have two channels- one for each Arduino. In addition I have generated one ThingSpeakPlot visualisation which is calculating the difference between counter 1 from channel 1 and counter 2 from channel 2. The result is depicted using 

[Counter1Data, time] = thingSpeakRead(readChannelID1, 'Fields', Counter1FieldID, 'NumPoints', 30,'ReadKey', readAPIKey1);
[Counter2Data, time] = thingSpeakRead(readChannelID2, 'Fields', Counter1FieldID, 'NumPoints', 30,'ReadKey', readAPIKey2);

Difference = Counter1Data - Counter2Data;

thingSpeakPlot(time, [Difference]);

Problem: when the chart is generated/depicted in either Channel 1 or 2 it does not automatically update itself, i.e. when the counter values change the plot/chart does not update...it only does, when I manually refresh the page or open it the first time.

I'd like to have a "living" chart as I have it when visualizing each channel counter value separately.

Any help is appreciated- Thanks!


irasch on Using ThingHTTP with Tropo

$
0
0

Hi,

I found a ThingHTTP app that will allow me to send SMS messages through Twilio from an Arduino. The instructions to set it up are below, and it works:

Copy the following data into the fields. Where italics and caps you must replace with the data from Twilio.

  1. Name it Twilio Send SMS
  2. URL is https://api.twilio.com/2010-04-01/Accounts/YOUR TWILIO ACCOUNT SID/SMS/Messages
  3. HTTP Auth Username is YOUR TWILIO ACCOUNT SID
  4. HTTP Auth Password is YOUR TWILIO AUTH TOKEN
  5. Set the method to POST
  6. Content type is application/x-www-form-urlencoded
  7. Click remove headers, and leave host blank
  8. Body = From=YOUR TWILIO NUMBER&To=%%number%%&Body=%%message%%

Click Save ThingHTTP

However, I'd like to use Tropo instead of Twilio.  Does anyone know how I'd set up the ThingHTTP app for Tropo instead of Twilio?

Thanks. 

Vinod on Using ThingHTTP with Tropo

$
0
0

Assuming you have a tropo URL like this:

https://api.tropo.com/1.0/sessions?action=create&token=***YOUR_TROPO_TOKEN_HERE***

you can create a new thingHTTP and set the URL parameter of the thingHTTP to the string above and hit save.

Now you have a ThingSpeak URL you can hit, like 

https://api.thingspeak.com/apps/thinghttp/send_request?api_key=***YOUR_THINGSPEAK_API_KEY*** 

and it should trigger tropo.

My recommendation is to first test your tropo link to confirm it works, then code it into a thingHTTP.

Vinod on Auto update ThingSpeakPlot charts

$
0
0

To confirm your request, you would like the plot generated using thingSpeakPlot to auto refresh every 'n' seconds? 

This is not possible today, but we will put it in the list of features to add based on user requirements. 

In the mean time, you could save the following into a simple HTML page. It auto reloads the page every 5 minutes. Instead of opening ThingSpeak.com, you would open this page.

<html lang="en">
 <body style="margin:0;padding:0">
   <iframe src="" id="myIFrame" style="border:none;" height="0" width="0"></iframe>
 </body>
 <script>
   var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
   var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
   var frameHdl = document.getElementById('myIFrame');
   frameHdl.src = "https://thingspeak.com/channels/YOURCHANNELNUMBER"
   frameHdl.height = height;
   frameHdl.width = width;
   window.setInterval("reloadPage();", 5*60*1000); //minutes to milliseconds 
   function reloadPage() {
     location.reload(true); 
   }
 </script> 
</html>

irasch on Using ThingHTTP with Tropo

$
0
0

I've made a little progress, but still have a problem. If I set up the Choreo like this:

 

Name: TropoSendSMS

APIKey: xxxxx

URL: https://api.tropo.com/1.0/sessions?action=create&token=***tropokey***&phone=6095551212&msg=Test2

Method: GET

Content Type: application/x-www-form-urlencoded

HTTP Version: 1.0

Host: https://api.tropo.com

Body: doesn't matter

It works. But since the phone number and message text are up in the URL, I can't substitute for them So I try to put them in the body:

 

Name: TropoSendSMS

APIKey: xxxxx

URL: https://api.tropo.com/1.0/sessions?action=create&token=***tropokey***

Method: GET

Content Type: application/x-www-form-urlencoded

HTTP Version: 1.0

Host: https://api.tropo.com

Body: &phone=6095551212&msg=Test2

It fails.  When I look at the Tropo error, it says that a phone number is not being provided. 

[I know that in the Body area I can make substitutions for the phone number and text, but for now I'm keeping it simple until the Choreo works.]

Any idea why moving the phone and message from the URL to the Body fails? 

Thanks. 

Vinod on Using ThingHTTP with Tropo

$
0
0

It could be because of some parsing of the '&' character. try replacing them with '&amp;'

That said, the right solution is the body substitutions.

Viewing all 223 articles
Browse latest View live