Node-red

Home Forums General Node-red

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #16573
    Akshay Bhavsar
    Participant

    Hi there,

    I am new to this.
    How to receive data from MTDOT to MultiConnect Conduit and showing on Node-Red as shown on following link

    But at 5:50, the guy has copied code from wordpad file for particular function. I don’t know how to get that and how can I write my own function. If there is any reference then please indicate.

    Your help would be great.

    Thanks
    Akshay

    #16577

    Hi Akshay

    You can drag a function node into NodeRED and write code in it. You can write the function code in your favorite editor then cut and paste into the function node. The video also shows a method of importing. Do whatever works best for how you like to work.

    Here is a link for writing functions in NodeRED
    https://nodered.org/docs/writing-functions

    Kind regards,
    Leon

    #16579
    Steve Kovarik
    Moderator

    Akshay

    Here is a link to the full “Flow” created at 5:50 in the video.
    This includes LoRaIn Node–>F(n) Node—>Debug Node

    And is intended for use with the MTDOT-BOX or EVB when selecting
    “LoRa Demo” mode of operation to parse out sensor data.

    https://webfiles.multitech.com/mmm/LoRa_Demo_ParserFlow.txt

    Thanks for watching

    #16607
    Akshay Bhavsar
    Participant

    @Leon I know the link, but there isn’t any full example for it, such as assigning data type and stuff.

    var data_type = {
    	none : 0x00,
    	led1 : 0x01,
    	led2 : 0x02,
    	lux_max : 0x03,
    	lux_min : 0x04,
    	lux_curr : 0x05,
    	baro_max : 0x06,
    	baro_min : 0x07,
    	baro_curr : 0x08,
    	temp_max : 0x09,
    	temp__min : 0x0A,
    	temp_curr : 0x0B,
    	accel_max : 0x0C,
    	accel_min : 0x0D,
    	accel_curr : 0x0E,
    	configuration : 0x0F,
    	gpio_in : 0x10,
    	gpio_out : 0x11,
    	current_max : 0x12,
    	current_min : 0x13,
    	current_curr : 0x14,
    	gps_latitude : 0x15,
    	gps_longitude : 0x16,
    	gps_time : 0x17,
    	gps_date : 0x18,
    	gps_lock : 0x19,
    	qos_up : 0x1A,
    	qos_dwn : 0x1B,
    	rf_out : 0x1C,
    	data_mark : 0x1D,
    };
    
    var data_struc = {
    	data_valid : 0,
    	block_start :0,
    	temperature : 0,
    	x_pos : 0,
    	y_pos : 0,
    	z_pos : 0,
    	baro_pressure : 0,
    	lux : 0,
    	pkt_timer :0,
    	rf_pwr : 0,
    	sf_val : 0,
    	rssi_up : 0,
    	snr_up : 0,
    	rssi_dwn : 0,
    	snr_dwn :0 ,
    	lat_deg : 0 ,
    	lat_min : 0,
    	long_deg : 0,
    	long_min : 0,
    	num_sats : 0 ,
    	gps_status : 0,
    };
    
    context.global.data_out = context.global.data_out || data_struc;
    var pData = context.global.data_out;
    
    var msg_pntr = 0;
    var temp = 0;
    
    while (msg_pntr < msg.payload.length){
    	switch (msg.payload[msg_pntr]){
    	case data_type.lux_max:
    	case data_type.lux_min:
    	case data_type.lux_curr:
    		pData.lux = msg.payload[++msg_pntr] << 8;
    		pData.lux |= msg.payload[++msg_pntr];
    		pData.lux = pData.lux * 0.24;
    		msg_pntr++;
    		break;
    	case data_type.baro_max:
    	case data_type.baro_min:
    	case data_type.baro_curr:
    		pData.baro_pressure = msg.payload[++msg_pntr]<<16;
    		pData.baro_pressure |= msg.payload[++msg_pntr]<<8;
    		pData.baro_pressure |= msg.payload[++msg_pntr];
    		pData.baro_pressure = pData.baro_pressure * 0.25;
    		msg_pntr++;
    		break;
    	case data_type.accel_max:
    	case data_type.accel_min:
    	case data_type.accel_curr:
    		pData.x_pos = ((msg.payload[++msg_pntr] << 24) >> 24) * 0.0625;
    		pData.y_pos = ((msg.payload[++msg_pntr] << 24) >> 24) * 0.0625;
    		pData.z_pos = ((msg.payload[++msg_pntr] << 24) >> 24) * 0.0625;
    		msg_pntr++;
    		break;
    	case data_type.temp_min:
    	case data_type.temp_max:
    	case data_type.temp_curr:
    		pData.temperature = msg.payload[++msg_pntr] << 24;
    		pData.temperature |= msg.payload[++msg_pntr] << 16;
    		pData.temperature = (pData.temperature >> 16) * 0.0625;
    		msg_pntr++;
    		break;
    	case data_type.configuration:
    		pData.pkt_timer = msg.payload[++msg_pntr];
    		msg_pntr++;
    		break;
    	case data_type.current_max:
    	case data_type.current_min:
    	case data_type.current_curr:
    		msg_pntr++;
    		msg_pntr++;
    		msg_pntr++;
    		break;
    	case data_type.gps_latitude:
    		pData.lat_deg = (msg.payload[++msg_pntr] << 24) >> 24;
    		pData.lat_min = msg.payload[++msg_pntr];
    		temp = msg.payload[++msg_pntr] << 8 ;
    		temp |= msg.payload[++msg_pntr];
    		pData.lat_min = pData.lat_min + (temp * 0.0001);
    		msg_pntr++;
    		break;
    	case data_type.gps_longitude:
    		pData.long_deg = (msg.payload[++msg_pntr] << 24);
    		pData.long_deg |= (msg.payload[++msg_pntr] << 16);
    		pData.long_deg = pData.long_deg >> 16;
    		pData.long_min = msg.payload[++msg_pntr];
    		temp = msg.payload[++msg_pntr] << 8;
    		temp |= msg.payload[++msg_pntr];
    		pData.long_min = pData.long_min + (temp * 0.0001);
    		msg_pntr++;
    		break;
    	case data_type.gps_time:
    		msg_pntr++;
    		msg_pntr++;
    		msg_pntr++;
    		msg_pntr++;
    		break;
    	case data_type.gps_date:
    		msg_pntr++;
    		msg_pntr++;
    		msg_pntr++;
    		msg_pntr++;
    		break;
    	case data_type.gps_lock:
    		msg_pntr++;
    		pData.gps_status = msg.payload[msg_pntr] & 0x0F;
    		pData.num_sats = msg.payload[msg_pntr++] >> 4;
    		break;
    	case data_type.qos_up:
    		pData.rssi_up = msg.payload[++msg_pntr] << 24;
    		pData.rssi_up |= msg.payload[++msg_pntr] << 16;
    		pData.rssi_up = pData.rssi_up >> 16;
    		pData.snr_up = (msg.payload[++msg_pntr] << 24) >> 24;
    		pData.rf_pwr = (msg.payload[++msg_pntr] << 24) >> 24;
    		msg_pntr++;
    		break;
    	case data_type.qos_dwn:
    		pData.rssi_dwn = msg.payload[++msg_pntr] << 24;
    		pData.rssi_dwn |= msg.payload[++msg_pntr] << 16;
    		pData.rssi_dwn = pData.rssi_dwn >> 16;
    		pData.snr_dwn = ((msg.payload[++msg_pntr] << 24) >> 24) / 4;
    		msg_pntr++;
    		break;
    	case data_type.rf_out:
    		pData.rf_pwr = (msg.payload[++msg_pntr] << 24) >> 24;
    		msg_pntr++;
    		break;
    	case data_type.data_mark:
    		if (msg_pntr == '0') {
    			pData = data_struc;
    			pData.block_start = 1;
    			msg_pntr++;
    		}
    		else if (msg_pntr == (msg.payload.length - 1) && (pData.block_start === 1)) {
    				pData.data_valid = 1;
    				msg_pntr++;
    			}
    			else {
    				pData = data_struc;
    				msg_pntr = msg.payload.length;
    				}
    		break;
    	default:
    		pData = data_struc;
    		msg_pntr = msg.payload.length;
    	}
    }
    
    pData.sf_val = parseInt(msg.datr.replace("SF","  "),10);
    
    context.global.data_out = pData;
    
    return pData;
    

    @steve Thanks man. It has created above code, but still I am not able to see data on Node-RED at debug window.

    When I deploy I am getting following error, what that means and how can I correct it ?

    ” mqtt-broker: staging.thethingsnetwork.org:1883 ”

    Thanks guys
    Akshay

    #16610
    Akshay Bhavsar
    Participant

    Hi guys,
    Don’t worry about the above error, I figure it out.

    Now the problem is I am note able to receive data on debug window of Node-RED. I am successfully able to join MTDOT-Box-G-915 to MultiConnect Conduit. When I run LoRa Demo from theMTDOT-Box-G-915 and send the the data not able to receive it on Node-RED.

    I have imported the code as @Steve Kovarik has suggested.

    So, What can be the issue ?

    Thanks
    Akshay

    #16621
    Akshay Bhavsar
    Participant

    Hi Steve,

    Is there any updates on this or the code you have provided might have something wrong in it. MTDOT-BOX-G-195 do join conduit box. When I run IP address of conduit box and check system log and under the LoRa tab it does shows the connection. I have used your code( as mentioned above thread) in Node-RED and send data from MTDOT-BOX, but do not able to see that in debug window.

    Your help would be great.

    Thanks
    Akshay

    #16622
    Steve Kovarik
    Moderator

    Hi Akshay

    I just downloaded and installed the flow from the FTP link I provided, and
    it worked fine. Another idea is to drag out a “Debug Output” node and
    connect it to the “LoRa Input” node and see if you receive anything in the
    debug tab. This will prove the gateway is receiving LoRa packets and can
    display them in the debug tab.

    #16623
    Akshay Bhavsar
    Participant

    Hi Steve,

    I did that, but not able to see anything on debug tab. It does join and I can see in statics. Have a look the image.

    #16624
    Akshay Bhavsar
    Participant

    #16625
    Akshay Bhavsar
    Participant
    #18876

    I added the javascript provided in the ftp link above. And on sending the message from EVB, i get the following error:

    “TypeError: Cannot read property ‘replace’ of undefined”

    #18877

    In addition, i am trying to push the data from EVB to the influx database.

    I can see the EVB messages in the payload, but they are not inserted into InfluxDB.

    But, when i inject with a simple timestamp from node-red, the message is stored in InfluxDB.

    Is the issue related to the formatting the EVB message?

    #18878

    Here is the image for my question above : https://ibb.co/j6Xpt5

    #18901

    In addition, i am trying to push the data from EVB to the influx database.

    I can see the EVB messages in the payload, but they are not inserted into InfluxDB.

    But, when i inject with a simple timestamp from node-red, the message is stored in InfluxDB.

    If i modify the java script provided by @Steve Kovarik to get only the temperature, it works.

    There is some issue wit this line in the java script :

    pData.sf_val = parseInt(msg.datr.replace(“SF”,” “),10);

    the variable “msg.datr” seems to be the issue.

    #19936
    Ricky Terzis
    Participant

    Hi…i also had the same question and i think you should follow as suggested above that you can drag a function node into NodeRED and write code in it. You can write the function code in your favorite editor then cut and paste into the function node.

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.