R. De Gruijter in MATLAB Answers
上次活动时间: 2025-4-10

See my post here for more info: <www.thethingsnetwork.org/forum/t/49946 https://www.thethingsnetwork.org/forum/t/payload-formatter-v3-how-to-return-rssi-and-snr-to-a-thingspeak-channel/49946> .In the payload formatter I cannot access information like SNR (signal to noise ratio) of a lorawan message. But this information is definitely available in the Things Stack. So how do I get this data into a ThingSpeak channel for recording?
Steven Grobler in Discussions
上次活动时间: 2024-5-10

I have a LORA node up-linking data to a Thingspeak channel via The Things Network (TTN). Sometimes it stops sending data and I reboot it by logging into my console on TTN and sending a re-boot down-link message to the node. Is there any way I can transmit a downlink message to the node direct from Thinkspeak? how to reboot a LORA node if it stops sending data? Is there an API call to trigger the downlink? If so, you can trigger from ThingSpeak via MATLAB analysis code using webwrite aor webread. Thanks Christopher, thanks for that - there is indeed an API for TTN. I shall investigate that further and I'll post back here with what I find... regards, Steve The TTN API documentation gives the following example of a downlink to the end device dev1 of the application app1 using the webhook wh1. curl --location \ --header 'Authorization: Bearer NNSXS.XXXXXXXXX' \ --header 'Content-Type: application/json' \ --header 'User-Agent: my-integration/my-integration-version' \ --request POST \ --data '{"downlinks":[{ "frm_payload":"vu8=", "f_port":15, "priority":"NORMAL" }] }' \ 'https://thethings.example.com/api/v3/as/applications/app1/webhooks/wh1/devices/dev1/down/push' I've tried to enter that information into my ThingHTTP, using my own parameters for dev1, app1, wh1 etc, including the Authorisation header with the bearer key from TTN and the Content-Type header. I do not know what to insert for the User-Agent header, so left that out. I tried sending the command from a CMD window in Windows 11, using curl as below, but I get a "-1" response, indicating a failure, and TTN does not receive the downlink either... Maybe the User-Agent header is essential . Any suggestions? curl "https://api.thingspeak.com/apps/thinghttp/send_request?api_key=my-api-key" User agent is not needed (thoug it can he helpful for statistics on our side). The -1 for ThingHTTP usually means authorization problem. You could check though by making the ThingHTTP just do something simple like update a channel. For flexibility, I would recomend you use a MATLAB analysis. Its a little harder to trigger from a device, but you can have a React set up from a channel, and when the device updates the channel, then the react will trigger the code. You get a lot more flexibility in what you can send from MATLAB code instead of the ThingHTTP UI. And its easier to develop and test code: if you have MATLAB desktop or usinging MATLAB onlineor the MATLAB AI chat playground (the last two have a free tier if needed). You can use webread or webwrite in your code to call other API's. weboptions can help wih the authorization and setting other headers. The playground can help you write the code also. thingspeak ttn reboot downlink
Vladimir Bazhenskiy in MATLAB Answers
上次活动时间: 2022-2-13

Hi, I try to send data using integration with TTN and no any data are shown on plots. I can send data from my web-browser successfully. Can I see any debug informatin about receiving data by ThingSpeak?
pema chowden in Discussions
上次活动时间: 2021-11-18

i am trying to decode the below sketch to integrate TTNv3 to thingspeak. can someone help me with this issue #include <lmic.h> #include <dht.h> #include <hal/hal.h> #include <SPI.h> dht DHT; #define DHT11_PIN 5 #define PIN_A A0 float temperature,humidity; float tem,hum; unsigned int count = 1; //For times count String datastring1=""; String datastring2=""; String datastring3=""; static uint8_t mydata[11] = {0x01,0x67,0x00,0x00,0x02,0x68,0x00,0x03,0x65,0x00,0x00}; /* LoRaWAN NwkSKey, network session key This is the default Semtech key, which is used by the prototype TTN network initially. ttn*/ static const PROGMEM u1_t NWKSKEY[16] = { 0x72, 0x13, 0xF8, 0xF0, 0x9A, 0x3C, 0xF9, 0xE5, 0xE6, 0x01, 0xDA,0xAC, 0x32, 0xBA, 0x37 }; /* LoRaWAN AppSKey, application session key This is the default Semtech key, which is used by the prototype TTN network initially. ttn*/ static const u1_t PROGMEM APPSKEY[16] = { 0x2F, 0xF5, 0xF4, 0x08, 0x4E, 0x37, 0x20, 0x02, 0xBA, 0x2B, 0xED, 0x40, 0x24, 0xA2, 0x945 }; /* LoRaWAN end-device address (DevAddr) See http://thethingsnetwork.org/wiki/AddressSpace ttn*/ static const u4_t DEVADDR = 0x260D0CA5; /* These callbacks are only used in over-the-air activation, so they are left empty here (we cannot leave them out completely unless DISABLE_JOIN is set in config.h, otherwise the linker will complain).*/ void os_getArtEui (u1_t* buf) { } void os_getDevEui (u1_t* buf) { } void os_getDevKey (u1_t* buf) { } static osjob_t initjob,sendjob,blinkjob; /* Schedule TX every this many seconds (might become longer due to duty cycle limitations).*/ const unsigned TX_INTERVAL = 10; // Pin mapping const lmic_pinmap lmic_pins = { .nss = 10, .rxtx = LMIC_UNUSED_PIN, .rst = 9, .dio = {2, 6, 7}, }; void do_send(osjob_t* j){ // Check if there is not a current TX/RX job running if (LMIC.opmode & OP_TXRXPEND) { Serial.println("OP_TXRXPEND, not sending"); } else { dhtTem(); light(); // Prepare upstream data transmission at the next possible time. // LMIC_setTxData2(1,datasend,sizeof(datasend)-1,0); LMIC_setTxData2(1, mydata, sizeof(mydata), 0); Serial.println("Packet queued"); Serial.print("LMIC.freq:"); Serial.println(LMIC.freq); Serial.println("Receive data:"); } // Next TX is scheduled after TX_COMPLETE event. } void onEvent (ev_t ev) { Serial.print(os_getTime()); Serial.print(": "); Serial.println(ev); switch(ev) { case EV_SCAN_TIMEOUT: Serial.println(F("EV_SCAN_TIMEOUT")); break; case EV_BEACON_FOUND: Serial.println(F("EV_BEACON_FOUND")); break; case EV_BEACON_MISSED: Serial.println(F("EV_BEACON_MISSED")); break; case EV_BEACON_TRACKED: Serial.println(F("EV_BEACON_TRACKED")); break; case EV_JOINING: Serial.println(F("EV_JOINING")); break; case EV_JOINED: Serial.println(F("EV_JOINED")); break; case EV_RFU1: Serial.println(F("EV_RFU1")); break; case EV_JOIN_FAILED: Serial.println(F("EV_JOIN_FAILED")); break; case EV_REJOIN_FAILED: Serial.println(F("EV_REJOIN_FAILED")); break; case EV_TXCOMPLETE: Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)")); if(LMIC.dataLen) { // data received in rx slot after tx Serial.print(F("Data Received: ")); Serial.write(LMIC.frame+LMIC.dataBeg, LMIC.dataLen); Serial.println(); } // Schedule next transmission os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send); break; case EV_LOST_TSYNC: Serial.println(F("EV_LOST_TSYNC")); break; case EV_RESET: Serial.println(F("EV_RESET")); break; case EV_RXCOMPLETE: // data received in ping slot Serial.println(F("EV_RXCOMPLETE")); break; case EV_LINK_DEAD: Serial.println(F("EV_LINK_DEAD")); break; case EV_LINK_ALIVE: Serial.println(F("EV_LINK_ALIVE")); break; default: Serial.println(F("Unknown event")); break; } } void setup() { // initialize digital pin as an output. Serial.begin(9600); while(!Serial); Serial.println("Connect to TTN and Send data to mydevice(Use DHT11 Sensor):"); #ifdef VCC_ENABLE // For Pinoccio Scout boards pinMode(VCC_ENABLE, OUTPUT); digitalWrite(VCC_ENABLE, HIGH); delay(1000); #endif // LMIC init os_init(); // Reset the MAC state. Session and pending data transfers will be discarded. LMIC_reset(); /*LMIC_setClockError(MAX_CLOCK_ERROR * 1/100); Set static session parameters. Instead of dynamically establishing a session by joining the network, precomputed session parameters are be provided.*/ #ifdef PROGMEM /* On AVR, these values are stored in flash and only copied to RAM once. Copy them to a temporary buffer here, LMIC_setSession will copy them into a buffer of its own again.*/ uint8_t appskey[sizeof(APPSKEY)]; uint8_t nwkskey[sizeof(NWKSKEY)]; memcpy_P(appskey, APPSKEY, sizeof(APPSKEY)); memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY)); LMIC_setSession (0x1, DEVADDR, nwkskey, appskey); #else // If not running an AVR with PROGMEM, just use the arrays directly LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY); #endif for (int channel=0; channel<8; ++channel) { LMIC_disableChannel(channel); } for (int channel=16; channel<72; ++channel) { LMIC_disableChannel(channel); } // Disable link check validation LMIC_setLinkCheckMode(0); // TTN uses SF9 for its RX2 window. LMIC.dn2Dr = DR_SF9; // Set data rate and transmit power (note: txpow seems to be ignored by the library) LMIC_setDrTxpow(DR_SF7,14); // Start job do_send(&sendjob); } void dhtTem() { int16_t tem1; temperature = DHT.read11(DHT11_PIN); //Temperature detection tem = DHT.temperature*1.0; float humidity = DHT.read11(DHT11_PIN); float hum = DHT.humidity* 1.0; Serial.print(F("########### ")); Serial.print(F("NO.")); Serial.print(count); Serial.println(F(" ###########")); Serial.println(F("The temperautre and humidity :")); Serial.print(F("[")); Serial.print(tem); Serial.print(F("℃")); Serial.print(F(",")); Serial.print(hum); Serial.print(F("%")); Serial.print(F("]")); Serial.println(""); count++; tem1=(tem*10); mydata[2] = tem1>>8; mydata[3]= tem1; mydata[6] = hum * 2; } void light(){ int16_t lux; int val,val1; val=analogRead(PIN_A); // Serial.print(F("a:")); //Serial.println(val); delay(500); val1=val*1.0; lux=val1; mydata[9]=lux>>8; mydata[10]=lux; //Serial.print(lux); } void loop() { os_runloop_once(); } payload decoder on TTN See <https://www.youtube.com/watch?v=b9Ga4nwnsTM this video> for some suggestions. What have you tried so far? What are you seeing? thank you, I tried the following decoder. i think I am reading the byte wrong function Decoder(bytes, port) { var tem = (bytes[2]<<8) | bytes[3]; var hum = (bytes[6])*2; return { field3: tem, field4: hum } } payload decode ttn thingspeak

关于 ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.