Getting Sensordata to TTN using MKRWAN 1310

Hello, I now have a programme that sends data to TTN using the ARD MKRWAN 1310. I also have a second program that displays the data from my vibration sensor (SEN-VIB01) in the serial plotter. now I don’t know how to merge the two programs so that the data of the virbationssensor getting send to TTN at a certain time interval. I will copy both programs below. I hope, someone got a clue how to merge these two programs, that i can see the vibrationData in TTN. I would be very grateful for any help, I have been working on this problem for days, but my programming skills are very poor.

Programm for connection to TTN:

#include <MKRWAN.h>
LoRaModem modem;

String appEui = “0000000000000000”;
String appKey = “…466”;

bool connected;
int err_count;

void setup() {
modem.begin(EU868);
delay(1000); // apparently the murata dislike if this tempo is removed…
connected=false;
err_count=0;
}

void loop() {

if ( !connected ) {
int ret=modem.joinOTAA(appEui, appKey);
if ( ret ) {
connected=true;
modem.minPollInterval(60);
modem.dataRate(5); // switch to SF7
delay(100); // because … more stable
err_count=0;
}
}
if ( connected ) {
int err=0;
modem.beginPacket();
modem.write(msg,12);
err = modem.endPacket(true);
if ( err <= 0 ) {
// Confirmation not received - jam or coverage fault
err_count++;
if ( err_count > 50 ) {
connected = false;
}
// wait for 2min for duty cycle with SF12 - 1.5s frame
for ( int i = 0 ; i < 120 ; i++ ) {
delay(1000);
}
} else {
err_count = 0;
// wait for 10s for duty cycle with SF7 - 55ms frame
delay(10000);
}
}
}Preformatted text

Programm for vibrationsensor:

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
}

  1. I hope you aren’t thinking you can send real-time vibration data over LoRaWAN? Do we assume you are looking to send some kind of alarm or statistics package….trigger on a peak value or r.m.s. level? Bundle of min, max, mean, median value over a set period etc?

  2. haven’t looked in detail but suspect your duty cycle timing may be out depending on payload size(s), and certainly likely to exceed TTN FUP, 1.5sec every couple of mins for SF12 would be major breach :wink:

As indeed would the SF7 value

Have you considered applying some edge processing on the node to classify the nature/type of vibration? Look for EdgeImpulse demo’s using TTN fro e.g. prior Things Conferences & online webinars etc…. :slight_smile:

In effect, if this is a recommended sketch from Arduino, for TTN, it appears to suggest thats its OK to send data at around 30 times the fair useage policy, as in what you get for free.

Nice one Arduino.

If someone points out the Github where the MKRWAN 13100 code comes from, an issue need to be raised.

I want to try to do something like a alarm. But i dont know how to programm. But this would be possible, if i would say maybe, if the value exceed there has to be a signal?
Or would it be possible to send packages like you said?

Would depend on if you are looking for a transient (a shock) or a min period of a sustained vibration of a paticular level. Either way I would look to do some basic signal conditioning and rather than then having the MCU runnng full time monitoring the signal for target conditions (with chance may also miss a short transient) I would look to perhaps drive a comparator and then triger a latched signal - to e.g. generate an interupt and wake the MCU to then send the alarm - much as might be done for a door/window open close sensor? Just thinking aloud… if a single period or event not of concern and not a reasn to trigger immediate alarm, on lowest latency, perhaps keep a tally of events and send a periodic message stating how many event since last message or alarm if more than x events in a given period…

Its not easy to sugegst solutions to your apparent problem, without knowing what the actual applications is …

Rather curious that that the MKRWAN script doesn’t define the payload variable.

Rather concerning that as well as breaching all sorts of laws & FUP that it’s using confirmed uplinks as well.

This looks like a piece of coursework to me and is in fact easily solved with the relevant section in the Learning documentation that’s linked to at the top of the every forum page.