Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 2 months ago.
Need Help with thingspeak and includes!
Hello guys!
I need help with some issues with a example program i got from http://www.frank-zhao.com/thingspeak_mbed_tut1/. I need this for a school project that uses thingspeak.
When i import all the includes:
- include "mbed.h"
- include "EthernetNetIf.h"
- include "NTPClient.h"
- include "HTTPClient.h"
i get the issue " Error: Identifier "TCPSocketConnection" is undefined in "HTTPClient/HTTPClient.h", Line: 145, Col: 4 "
So then i thought that i would include Socket.h and EthernetInterface.h from mbed-os with no luck.
Any ideas to how i can fix this issue? Thanks in advance.
The code used :
- include "mbed.h"
- include "EthernetNetIf.h"
- include "NTPClient.h"
- include "HTTPClient.h"
- include "Socket.h"
- include "EthernetInterface.h" networking stuff
EthernetNetIf eth;
NTPClient ntp;
HTTPClient http;
char* ntpServerUrl = "0.ca.pool.ntp.org";
char* thingSpeakUrl = "http://api.thingspeak.com/update";
char* thingSpeakKey = "IS6YCLKIR423VO5H";
char urlBuffer[256];
char timeBuffer[64];
pin defs
DigitalOut rst(p30);
DigitalOut clk(p29);
DigitalInOut dq(p28);
void DS1620Send(long data, int numOfBits)
{
dq.output(); we are sending
for (int i = 0; i < numOfBits; i++)
{
clk = 0;
wait_us(0.05);
if (data & (1 << i)) bit is 1
{
dq = 1;
}
else bit is 0
{
dq = 0;
}
wait_us(0.5);
clk = 1;
wait_us(0.5);
}
dq.input(); go back to being input
clk = 1; leave high
}
float DS1620ReadTemp()
{
rst = 1;
DS1620Send(0xAA, 8); read temp command
dq.input();
int results = 0;
read in 9 bits
for (int i = 0; i < 9; i++)
{
clk = 0;
wait_us(0.5);
clk = 1;
wait_us(0.05);
if (dq.read() != 0) bit is 1
{
if (i < 8)
{
results |= 1 << i;
}
else
{
results *= -1; last bit is sign bit
}
}
wait_us(0.4);
}
clk = 1; leave high
rst = 0;
return (float)results / 2; div by 2 since last bit is 0.5
}
void DS1620Setup()
{
initial pin states
rst = 0;
clk = 1;
dq.input();
wait(0.1);
rst = 1;
DS1620Send(0x0A0C, 16); config for continuous mode with CPU mode
rst = 0;
wait(0.1);
rst = 1;
DS1620Send(0xEE, 8); start continuous conversions
rst = 0;
wait(0.1);
}
int main() {
printf("Start\r\n");
printf("Setting up Ethernet...\r\n");
EthernetErr ethErr = eth.setup();
if(ethErr)
{
printf("Error %d in ethernet setup.\r\n", ethErr);
return -1;
}
printf("Ethernet setup OK\r\n");
get time from ntp
time_t ctTime;
Host server(IpAddr(), 123, ntpServerUrl);
ntp.setTime(server);
start the sensor
DS1620Setup();
while(1)
{
update data here
ctTime = time(NULL);
float temperature = DS1620ReadTemp();
format time here
timeBuffer[0] = 0;
strftime(timeBuffer, 64, "%Y-%m-%d %H:%M:%S", localtime(&ctTime));
for debug
printf("Time: %s, Temperature: %f\r\n", timeBuffer, temperature);
format url here
urlBuffer[0] = 0;
sprintf(urlBuffer, "%s?key=%s&field1=%s&field2=%f", thingSpeakUrl, thingSpeakKey, timeBuffer, temperature);
printf("Request to %s\r\n", urlBuffer);
HTTPText resp;
HTTPResult res = http.get(urlBuffer, &resp);
if (res == HTTP_OK)
{
printf("Result :\"%s\"\r\n", resp.gets());
}
else
{
printf("Error %d\r\n", res);
}
wait(16); limited by ThingSpeak's API
}
return 0;
}
2 Answers
5 years, 1 month ago.
Hello, Hakon! I think you may find some useful information from this https://justbuyessay.com/blog/buy-essays-online-safe website!
5 years ago.
I solved this problem in the programming language delphi. Here are some tips to help you. The implementation of the program by means of the language also has a number of aspects that should not be passed. The main mistake that novice programmers make is the incorrect naming of functions, variables, constants. I also suffered from this and this, therefore I simply have to warn others. If you still fail to complete the tasks, use the task assistance service https://homeworkneeded.com. Usually at the very beginning you give variables the names of one letter: a, b, c, and so on. Agree, when a lot of variables are accumulated (and this happens quite quickly) it becomes simply impossible to remember what “a” is and what about “c”. Therefore, first of all, give “speaking” names to variables and constants: for example, Version contains the version of the program, and Index stores some number in it.
Are you using OS5 or OS2.
Either make sure you have the right Ethernet interface, see here:
https://os.mbed.com/users/mbed_official/code/EthernetInterface/
Also use this for your code when asking questions:
include the mbed library with this snippet
See editing tips 'code'
Can you remove your duplicate question.
posted by Paul Staron 08 Feb 2019