How to use split function in node js

180
January 19, 2020, at 5:40 PM

I have combined two strings at the client side to publish on a topic

client.publish(topic,payload = String(message)+","+String(weather))

I receive them at the server side as a string But this are two different messages which I have to send at two different http address I want to split the message at the server end But the split function is not working

This is the error message.
TypeError: Cannot read property 'split' of undefined

//MQTT publisher
var mqtt = require('mqtt')
var fetch = require('node-fetch')
var client = mqtt.connect('mqtt://localhost:1884')
var topic = 'local/temperature'
//var message = 'The status of weather station'
client.on('connect',()=>{
setInterval(async function(req,res){
        let weatherResponse = await fetch("https://api.openweathermap.org/data/2.5/weather?q=villingen-schwenningen,de&units=metric&appid=4b66b441cf82f4bca0467ecebb363a79");
        let weatherObj = await weatherResponse.json()
        let temperature = weatherObj.main.temp
        let message = JSON.stringify(temperature)
        let weather = JSON.stringify(weatherObj)
        client.publish(topic,payload = String(message)+","+String(weather))
        console.log(payload)
        console.log('Temperature value sent!')
        console.log('The temperature is',message)
    },3000)
})
//MQTT server (mosca broker)
const mosca = require("mosca")
var temperature = 0; 
moscaSettings = {
    host: "localhost",
    port: 1884,
    persistence: { factory: mosca.persistence.Memory }
}
var server = new mosca.Server(moscaSettings);
server.on('clientConnected', function(client) {
    console.log('client connected', client.id);
});
server.on('published', function(packet, client) {
    console.log('Published', packet.payload.toString());
    // I want to split the payload here 
    //console.log(info);
});
server.on('ready', setup);
function setup() {
    console.log('Mosca server is up and running on port '+ moscaSettings.port);
}
Rent Charter Buses Company
READ ALSO
How to use _id in mongoose's findOneAndUpdate filter?

How to use _id in mongoose's findOneAndUpdate filter?

I found find by _id with Mongoose after not being able to use findOneAndUpdate by setting an _id in the filterThe answer says I must define it in the Schema

196
start process in nodejs server , and for each answer send res in Angular

start process in nodejs server , and for each answer send res in Angular

hey im trying to create some process by get request and return it frequesy in my angular application

147
How to run a Python Script (On Linux) from a nodejs server (running on windows)

How to run a Python Script (On Linux) from a nodejs server (running on windows)

I have a nodejs server running on Windows 10My server needs to create thumbnails of pdfs, docx, images, etc from user uploaded files

173