Unable to Post Data on Channel
Show older comments
Hi,
I have some difficult to post data on channel.
The AP KEY for writing is : XXX
The AP KEY for reading : YYY
When I try to make GET or POST request (from Chrome or Postman) the result is always 0.
I didn't understand why, I follow too tutorial and try with Postman but always 0.
Thanks for your help.
Besy Regards
Accepted Answer
More Answers (5)
Julien Jacquemet
on 15 Jan 2020
0 votes
Andrzej Bieniek
on 25 Jan 2020
Edited: Vinod
on 27 Jan 2020
0 votes
Hi,
I have the same problem with my channel, I always get 0, could you help?
curl "https://api.thingspeak.com/update?api_key=MY_API_KEY&field1=1&field2=2"
0
1 Comment
Andrew St Clair
on 2 Feb 2020
Edited: Andrew St Clair
on 2 Feb 2020
I am also having this issue. no matter what i do, i always get 0
EDIT:
the code responsible for uploading the data looks like this (Arduino Code):
HttpClient client;
humidity = DHT.getHumidity();
temp = DHT.getTemperature();
client.get("https://api.thingspeak.com/update?api_key=XXX&field1="+String((int)temp)+"&field2="+String((int)humidity)+"&field3="+String(dewPoint((int)temp, (int)humidity)));
6 Comments
Damian Sikora
on 10 Feb 2020
Hi,
I think I have same problem - missed linking deadline - could you reset my account too?
Vinod
on 11 Feb 2020
Damian: Your account should be re-enabled. Please let me know if you still have any trouble.
Jacob Ask Hansen
on 16 Feb 2020
I seem to have the same issue, and probably also miseed the deadline.
pavel heimlich
on 20 Feb 2020
Hi,
I've got the same problem, could you reset my account? thanks!
Vinod
on 20 Feb 2020
@Pavel: Try again. You may have to log out of ThingSpeak and log back in.
peter veres
on 9 Feb 2020
0 votes
Hi everybody
I created 3 channels, humidity - temperature - altitude. (channel ID 979451)
Using Raspbery Pi4 + BMP180 sensor I see that data for 3 fields are uploading but not showing on chart at all:
Is refreshing every 5 seconds, reading correct data, but not showing on channel. Even I tryed to change API key, without success.
Does somebody has any ideea why?
Thank you
9 Comments
Vinod
on 11 Feb 2020
Peter: I don't see any data in your channel. Can you share your code on the pi? (please redact the API keys).
peter veres
on 12 Feb 2020
Hi
Here is the main program:
******************************************************************************************************
import sys
import RPi.GPIO as GPIO
import os
import Adafruit_DHT
import urllib.request
import smbus
import time
from ctypes import c_short
from Adafruit_BMP085 import BMP085
DHTpin = 22
key="XXXXXXXXXXXXXXXXXXXXXXXX" # Enter your Write API key from ThingSpeak
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
def readDHT():
humi, temp = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, DHTpin)
return (str(int(humi)), str(int(temp)))
# ===========================================================================
# Example Code
# ===========================================================================
# Initialise the BMP085 and use STANDARD mode (default value)
bmp = BMP085(0x77, debug=True)
#bmp = BMP085(0x77)
# To specify a different operating mode, uncomment one of the following:
# bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode
# bmp = BMP085(0x77, 1) # STANDARD Mode
# bmp = BMP085(0x77, 2) # HIRES Mode
# bmp = BMP085(0x77, 3) # ULTRAHIRES Mode
temp = bmp.readTemperature()
# Read the current barometric pressure level
pressure = bmp.readPressure()
# To calculate altitude based on an estimated mean sea level pressure
# (1013.25 hPa) call the function as follows, but this won't be very accurate
altitude = bmp.readAltitude()
# To specify a more accurate altitude, enter the correct mean sea level
# pressure level. For example, if the current pressure level is 1023.50 hPa
# enter 102350 since we include two decimal places in the integer value
# altitude = bmp.readAltitude(102350)
print ("Temp: %.2f C" % temp)
print ("Pressure: %.2f hPa" % (pressure / 100.0))
print ("Altitude: %.2f" % altitude)
def main():
print ('System Ready...')
URL = 'https://api.thingspeak.com/update?api_key=%s' % key
print ("Wait....")
while True:
(humi, temp)= readDHT()
(pressure) = pressure#readBmp180()
finalURL = URL +"&field1=%s&field2=%s"%(humi, temp)+"&field3=%.3s" %(altitude)
print (finalURL)
s=urllib.request.Request(finalURL);
if __name__=="__main__":
*************************************************************************************************************
This is calling another program:BMP085, this is calculating the values:
***************************************************************************************************************
import time
from Adafruit_I2C import Adafruit_I2C
# ===========================================================================
# BMP085 Class
# ===========================================================================
class BMP085 :
i2c = None
# Operating Modes
__BMP085_ULTRALOWPOWER = 0
__BMP085_STANDARD = 1
__BMP085_HIGHRES = 2
__BMP085_ULTRAHIGHRES = 3
# BMP085 Registers
__BMP085_CAL_AC1 = 0xAA # R Calibration data (16 bits)
__BMP085_CAL_AC2 = 0xAC # R Calibration data (16 bits)
__BMP085_CAL_AC3 = 0xAE # R Calibration data (16 bits)
__BMP085_CAL_AC4 = 0xB0 # R Calibration data (16 bits)
__BMP085_CAL_AC5 = 0xB2 # R Calibration data (16 bits)
__BMP085_CAL_AC6 = 0xB4 # R Calibration data (16 bits)
__BMP085_CAL_B1 = 0xB6 # R Calibration data (16 bits)
__BMP085_CAL_B2 = 0xB8 # R Calibration data (16 bits)
__BMP085_CAL_MB = 0xBA # R Calibration data (16 bits)
__BMP085_CAL_MC = 0xBC # R Calibration data (16 bits)
__BMP085_CAL_MD = 0xBE # R Calibration data (16 bits)
__BMP085_CONTROL = 0xF4
__BMP085_TEMPDATA = 0xF6
__BMP085_PRESSUREDATA = 0xF6
__BMP085_READTEMPCMD = 0x2E
__BMP085_READPRESSURECMD = 0x34
# Private Fields
_cal_AC1 = 0
_cal_AC2 = 0
_cal_AC3 = 0
_cal_AC4 = 0
_cal_AC5 = 0
_cal_AC6 = 0
_cal_B1 = 0
_cal_B2 = 0
_cal_MB = 0
_cal_MC = 0
_cal_MD = 0
# Constructor
def __init__(self, address=0x77, mode=1, debug=False):
self.i2c = Adafruit_I2C(address)
self.address = address
self.debug = debug
# Make sure the specified mode is in the appropriate range
if ((mode < 0) | (mode > 3)):
if (self.debug):
print ("Invalid Mode: Using STANDARD by default")
self.mode = self.__BMP085_STANDARD
else:
self.mode = mode
# Read the calibration data
self.readCalibrationData()
def readS16(self, register):
"Reads a signed 16-bit value"
hi = self.i2c.readS8(register)
lo = self.i2c.readU8(register+1)
return (hi << 8) + lo
def readU16(self, register):
"Reads an unsigned 16-bit value"
hi = self.i2c.readU8(register)
lo = self.i2c.readU8(register+1)
return (hi << 8) + lo
def readCalibrationData(self):
"Reads the calibration data from the IC"
self._cal_AC1 = self.readS16(self.__BMP085_CAL_AC1) # INT16
self._cal_AC2 = self.readS16(self.__BMP085_CAL_AC2) # INT16
self._cal_AC3 = self.readS16(self.__BMP085_CAL_AC3) # INT16
self._cal_AC4 = self.readU16(self.__BMP085_CAL_AC4) # UINT16
self._cal_AC5 = self.readU16(self.__BMP085_CAL_AC5) # UINT16
self._cal_AC6 = self.readU16(self.__BMP085_CAL_AC6) # UINT16
self._cal_B1 = self.readS16(self.__BMP085_CAL_B1) # INT16
self._cal_B2 = self.readS16(self.__BMP085_CAL_B2) # INT16
self._cal_MB = self.readS16(self.__BMP085_CAL_MB) # INT16
self._cal_MC = self.readS16(self.__BMP085_CAL_MC) # INT16
self._cal_MD = self.readS16(self.__BMP085_CAL_MD) # INT16
if (self.debug):
self.showCalibrationData()
def showCalibrationData(self):
"Displays the calibration values for debugging purposes"
# print ("DBG: AC1 = %6d" % (self._cal_AC1))
# print ("DBG: AC2 = %6d" % (self._cal_AC2))
# print ("DBG: AC3 = %6d" % (self._cal_AC3))
# print ("DBG: AC4 = %6d" % (self._cal_AC4))
# print ("DBG: AC5 = %6d" % (self._cal_AC5))
# print ("DBG: AC6 = %6d" % (self._cal_AC6))
# print ("DBG: B1 = %6d" % (self._cal_B1))
# print ("DBG: B2 = %6d" % (self._cal_B2))
# print ("DBG: MB = %6d" % (self._cal_MB))
# print ("DBG: MC = %6d" % (self._cal_MC))
# print ("DBG: MD = %6d" % (self._cal_MD))
def readRawTemp(self):
"Reads the raw (uncompensated) temperature from the sensor"
self.i2c.write8(self.__BMP085_CONTROL, self.__BMP085_READTEMPCMD)
time.sleep(0.005) # Wait 5ms
raw = self.readU16(self.__BMP085_TEMPDATA)
if (self.debug):
#print ("DBG: Raw Temp: 0x%04X (%d)" % (raw & 0xFFFF, raw))
return raw
def readRawPressure(self):
"Reads the raw (uncompensated) pressure level from the sensor"
self.i2c.write8(self.__BMP085_CONTROL, self.__BMP085_READPRESSURECMD + (self.mode << 6))
if (self.mode == self.__BMP085_ULTRALOWPOWER):
time.sleep(0.005)
elif (self.mode == self.__BMP085_HIGHRES):
time.sleep(0.014)
elif (self.mode == self.__BMP085_ULTRAHIGHRES):
time.sleep(0.026)
else:
time.sleep(0.008)
msb = self.i2c.readU8(self.__BMP085_PRESSUREDATA)
lsb = self.i2c.readU8(self.__BMP085_PRESSUREDATA+1)
xlsb = self.i2c.readU8(self.__BMP085_PRESSUREDATA+2)
raw = ((msb << 16) + (lsb << 8) + xlsb) >> (8 - self.mode)
if (self.debug):
#print ("DBG: Raw Pressure: 0x%04X (%d)" % (raw & 0xFFFF, raw))
return raw
def readTemperature(self):
"Gets the compensated temperature in degrees celcius"
UT = 0
X1 = 0
X2 = 0
B5 = 0
temp = 0.0
# Read raw temp before aligning it with the calibration values
UT = self.readRawTemp()
X1 = ((UT - self._cal_AC6) * self._cal_AC5) >> 15
X2 = (self._cal_MC << 11) / (X1 + self._cal_MD)
B5 = X1 + X2
temp = (int(B5 + 8) >> 4) / 10.0
if (self.debug):
#print ("DBG: Calibrated temperature = %f C" % temp)
return temp
def readPressure(self):
"Gets the compensated pressure in pascal"
UT = 0
UP = 0
B3 = 0
B5 = 0
B6 = 0
X1 = 0
X2 = 0
X3 = 0
p = 0
B4 = 0
B7 = 0
UT = self.readRawTemp()
UP = self.readRawPressure()
# You can use the datasheet values to test the conversion results
# dsValues = True
dsValues = False
if (dsValues):
UT = 27898
UP = 23843
self._cal_AC6 = 23153
self._cal_AC5 = 32757
self._cal_MB = -32768;
self._cal_MC = -8711
self._cal_MD = 2868
self._cal_B1 = 6190
self._cal_B2 = 4
self._cal_AC3 = -14383
self._cal_AC2 = -72
self._cal_AC1 = 408
self._cal_AC4 = 32741
self.mode = self.__BMP085_ULTRALOWPOWER
if (self.debug):
self.showCalibrationData()
# True Temperature Calculations
X1 = ((UT - self._cal_AC6) * self._cal_AC5) >> 15
X2 = (self._cal_MC << 11) / (X1 + self._cal_MD)
B5 = X1 + X2
if (self.debug):
#print ("DBG: X1 = %d" % (X1))
#print ("DBG: X2 = %d" % (X2))
#print ("DBG: B5 = %d" % (B5))
#print ("DBG: True Temperature = %.2f C" % ((int(B5 + 8) >> 4) / 10.0))
# Pressure Calculations
B6 = B5 - 4000
X1 = (int(self._cal_B2) * int(B6 * B6) >> 12) >> 11
X2 = (int(self._cal_AC2) * int(B6)) >> 11
X3 = X1 + X2
B3 = (((self._cal_AC1 * 4 + X3) << self.mode) + 2) / 4
if (self.debug):
#print ("DBG: B6 = %d" % (B6))
#print ("DBG: X1 = %d" % (X1))
#print ("DBG: X2 = %d" % (X2))
#print ("DBG: X3 = %d" % (X3))
#print ("DBG: B3 = %d" % (B3))
X1 = int(self._cal_AC3 * B6) >> 13
X2 = (int(self._cal_B1) * (int(B6 * B6) >> 12)) >> 16
X3 = ((X1 + X2) + 2) >> 2
B4 = (self._cal_AC4 * (X3 + 32768)) >> 15
B7 = (UP - B3) * (50000 >> self.mode)
if (self.debug):
#print ("DBG: X1 = %d" % (X1))
#print ("DBG: X2 = %d" % (X2))
#print ("DBG: X3 = %d" % (X3))
#print ("DBG: B4 = %d" % (B4))
#print ("DBG: B7 = %d" % (B7))
if (B7 < 0x80000000):
p = (B7 * 2) / B4
else:
p = (B7 / B4) * 2
if (self.debug):
#print ("DBG: X1 = %d" % (X1))
X1 = (int(p) >> 8) * (int(p) >> 8)
X1 = (X1 * 3038) >> 16
X2 = (-7357 * int(p)) >> 16
if (self.debug):
#print ("DBG: p = %d" % (p))
#print ("DBG: X1 = %d" % (X1))
#print ("DBG: X2 = %d" % (X2))
p = p + ((X1 + X2 + 3791) >> 4)
if (self.debug):
#print ("DBG: Pressure = %d Pa" % (p))
return p
def readAltitude(self, seaLevelPressure=101325):
"Calculates the altitude in meters"
altitude = 0.0
pressure = float(self.readPressure())
altitude = 44330.0 * (1.0 - pow(pressure / seaLevelPressure, 0.1903))
if (self.debug):
#print ("DBG: Altitude = %d" % (altitude))
return altitude
return 0
*************************************************************************************************************
The last called is Adafruit_I2C . I suppose you don't need it...
Anyway the running script ends on this:
Temp: 27.50 C
Pressure: 1005.29 hPa
Altitude: 66.92
Wait....
https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXX&field1=16&field2=24&field3=66.
https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXX&field1=8&field2=28&field3=66.
https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXX&field1=9&field2=29&field3=66.
https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXX&field1=9&field2=29&field3=66.
.....AND KEEP DOING THIS WITHOUT SHOWING ON CHARTS....
If you have some ideea why not, please help me
Thank you
Peter Veres
Vinod
on 13 Feb 2020
I think you need to add this line:
response = urllib.request.urlopen(s)
right after this line:
s=urllib.request.Request(finalURL)
peter veres
on 13 Feb 2020
Thanks
Now is showing all what I need...
I included also the DHT11 sensor for humidity.
How can I check outside my channel? What is the address?
Best regards
Peter
peter veres
on 13 Feb 2020
I found it...thanks
peter veres
on 15 Feb 2020
Now, after all my reading are working I have a new question:
Is there any option to feed live images from Pi camera?
Thinking something like live meteorological station with data readings and live feed from a camera...
Or, even to set some alarm threesholds like temp between 20-25 degrees, send alarm to an email address.
Does anybody tryed something similar?
Thanks
Peter
Vinod
on 20 Feb 2020
Alerts are certainly possible.
peter veres
on 21 Feb 2020
Thank you I can see the post.
Something like this it's in my mind:
I see a picture from the plant. It is live feed or just a picture?
Didn't found refference about how to embed live feed from pi camera in Thingspeek...
Do you have tips where to look?
Thank you again
Peter
Vinod
on 21 Feb 2020
If you have an IP camera that is pointed at your plant, you can have that image embedded on your ThingSpeak channel. It's not a streaming video, but it is a live image taken when the page is refreshed.
Here's an example:
1) Create a new MATLAB visualization and put this code in it:
imshow(webread('http://24.73.89.162/axis-cgi/jpg/image.cgi',weboptions('ContentType','image')),'border','tight');
2) Add this MATLAB visualization to your channel's view.
If you have an Android phone, you can get one of the many IP camera apps and try it out pretty easily.
peter veres
on 22 Feb 2020
0 votes
Hi again
I mentioned that I want to use the Pi camera, not IP Camera. A refreshed image will be enough.
How can I embed the image captured to Thingspeak? And the refreshment of the measurements also?
Some ideea please? How tocreate a channel for the picture?
Do I need fixed IP address? I suppose not.
Thank you
Peter
1 Comment
Communities
More Answers in the ThingSpeak Community
Categories
Find more on ThingSpeak in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!