HTTP integration


(Matic S) #41

Hi!

I have a question about how ACK messages (Device->Cloud) in the case of confirmed transmission (initiated in direction Cloud->Device) could be seen by our application via HTTP integration.

We send confirmed messages, but looks like TTN doesn’t send the ACK messages to our HTTP endpoint, or maybe we are logging the input messages incorrectly. We don’t see them due to that.

We are logging all HTTP input on our HTTP endpoint
(by HTTP endpoint, I refer to path which is being called by TTN once a message is received).

Thanks & cheers!


(Especial) #42

I did samething as you did except put my own url which is
https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/kwloratest1/especial_http?key=ttn-account-v2.uvH4zcJhiVuOTbECDfAcfuLTDEbarx_Dtd98HJhR4-g

but i only got
-> {“dev_id”:“arduino_lora_test2”,“payload_raw”:“AAE=”}
Errorcode:
and no data on ttn

I’m trying to looking for downlink please help me (sorry for my bad english ㅠㅠ)


(Especial) #43

I solve my problem!

I just thought “dev_id” is no important data so, I remainded as “hrmansenuno”
after i changed into my own dev_id it works!


(Callum Taylor) #44

Hi,

Sorry to bring up a new issue on an older form. I have tried absolutely everywhere online, and I still can’t seem to get uplink data from TTN sent to my website to work. In the TTN HTTP integration fields, I have used the default access key, my website with the PHP file on the end (e.g. http://websitename.com/file.php - obviously websitename is different) and the method as POST. On the PHP side, I have tried using MYSQL and writing to text files but I get absolutely nothing. When looking at the devices accessing my website I can clearly see TTN sending data. To simplify the code to find the root of the problem, I have used this code in by ‘file.php’ from the posts above (slightly modified):

<?php

//Make sure that it is a POST request.
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
    throw new Exception('Request method must be POST!');
}
 
//Make sure that the content type of the POST request has been set to application/json
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if(strcasecmp($contentType, 'application/json') != 0){
    throw new Exception('Content type must be: application/json');
}
 
//Receive the RAW post data.
$content = trim(file_get_contents("php://input"));
 
//Attempt to decode the incoming RAW post data from JSON.
$decoded = json_decode($content, true);
 
//If json_decode failed, the JSON is invalid.
if(!is_array($decoded)){
    throw new Exception('Received content contained invalid JSON!');
}

//Process the JSON.

echo $decoded; // Can I simply echo the decoded?

?>

When I try to see if it works, I go to the website URL directly (http://websitename.com/file.php) and then simulate an uplink in TTN console. It only displays the thrown error ‘Request method must be POST!’ or if I remove this, then nothing. What am I doing wrong? Should I have any other files in my website directory which has code relevant to file.php? Could it have something to do with my hosting, which is GoDaddy? Let me know if I can make it clearer in any way or try anything.

Thanks


(Arjan) #45

Where do you expect the output to go to? The HTTP integration is a server-to-server interface; when TTN connects to your server, it’s not going to handle the response you’re sending using the line above. Rather than echo-ing the request back to TTN, you’ll need to store it somewhere.

It doesn’t make sense that you’re going to that URL: even when TTN also goes to that URL at exactly the very same time (unlikely), there’s nothing in your code to make you (the human) show whatever TTN sent to that URL. Each request is a standalone request; nothing is shared with others who happen to know the same URL.

As a bare minimum without any security, this example from Parsing HTTP integration data in PHP might help:


(Callum Taylor) #46

Thank you so much. I failed to mention that I am a complete novice to PHP and I was thinking in terms of C++ and getting it simply to display data it receives. I feel very silly right now.

Thanks again.