Sending commands back to raspberry pi from bluemix node red - raspberry-pi

I am reading sensor values from Raspberry Pi 2 and sending it to bluemix IoT platform using node-red application on the Pi. After monitoring the values, I would like to send the command back to raspberry pi from the node red starter in the bluemix to control the GPIO on the Pi using node red application on the Pi.
I am able to send the data from the raspberry pi to the Bluemix using Node Red, and the data is also displayed on the node red starter in Bluemix (ibmiotin node). But the command from the bluemix to the Pi is not being sent.
When I try to send command by using the inject node to the PI, then the command is sent perfectly, but when I use the sensor input node to send the command, the command is not sent to the device.
Is there any criteria in the Bluemix that the same device can't be used for sending and receiving the data simultaneously?
How can I send the data back to the raspberry pi using the bluemix node-red starter?
P.S. Both the devices(sensor and Pi) are shown as connected in the IoT dashboard and also in node-red.
The image of my node red in bluemix is as shown below.

I just needed to add a json node before the ibmiot out node to send the commands to the device.
This solved the problem.
The updated flow is follows:

have a look on publish and subscribing to commands:
https://console.ng.bluemix.net/docs/services/IoT/applications/mqtt.html
You can use an mqtt node to publish and subscribe to the commands topic, parse the command in a function node then send it to your Pi through GPIO node

Related

Raspberry Pi connection and process image data

Does anyone know how to connect the Raspberry Pi to the cloud server after acquiring the image, how to send the processed data back to the Raspberry Pi after the cloud server processes it?

Can not communicate sparkun OBDII UART with Raspberry pi 4 over (minicom)

I'm trying to use Sparkfun's OBD-II-UART board to interface with a CAN network using a Raspberry pi 4. Upon connecting to sudo screen /dev/ttyAMA0 and when I send the commands, I'm not able to get any response from the OBD-II-UART board. Can anyone suggest why it is not communicating?

rosserial_server wifi connection Raspberry pi ESP8266

This post is related to ROS (Robot Operating System) and ESP8266, and has also been cross-posted on ROS Answers and Robotics Stack Exchange.
I've ROS Melodic running on a Raspberry Pi 4 and need to send out information (as strings) over wifi to multiple ESP8266. I'm only just starting so it's just one ESP8266 for now. For communication, I'm using socket_node found in the ROS package rosserial_server (package wiki).
Referring to the picture below, the slave node publishes to the topic /Topic_data_over_wifi which is subscribed by a node running on the ESP8266:
The problem is, the node /rosserial_server_socket_node remains floating!
I've double checked names of topics and IP addresses, and at one point, got the node /rosserial_server_socket_node to actually link to the rest of the ROS network as shown in the "What I want" section. However, that was just one time (a fluke?) and never could I again get /rosserial_server_socket_node to join the ROS network.
rosserial_server's socket_node is used with its default settings (port 11411). I did try other port numbers but there was no difference. After all nodes have been launched, here's the output of rostopic list (other than the usual /rosout and /rosout_agg):
/commands_from_master_node
/topic_data_over_wifi
Goal: I need to find a way to connect the ESP8266 and the Raspberry pi 4 over wifi using ROS. More specifically, I need to get data from the slave node (on Raspberry Pi) to the node running on the ESP8266.
I've already looked at this multiple-TCP-connections post but didn't find anything that could solve my problem.
Any inputs/suggestions will be very appreciated.
Depending on the software running on the ESPs, it might be an option to use the ROS MQTT bridge. The downside is that you will need an additional MQTT broker (I am not sure, but as I recall mqtt_bridge is an MQTT client and requires a broker like Mosquitto). You can add MQTT clients to the ESPs and connect them to the same broker and subscribe to MQTT messages. In other words, you create a MQTT network for the ESPs with their borker and add ROS to that network, via mqtt_bridge. If you are not running ROS specific software on the ESPs it should work fine.

How to get the device id of Raspberry Pi while sending data to IBM Bluemix as a gateway

I am sending data from Sense HAT (device) through a Raspberry Pi (gateway) to my Bluemix application. My Pi is also sending CPU temperature of Raspberry Pi to Bluemix. I have one IBM IoT node receiving both of the data. I am not able to differentiate the Sense HAT data from Raspberry Pi data. Here is the function node code:
var v;
if(msg.deviceId==="raspberryID")
{
v= "From Raspberry Pi";
}
else if (msg.deviceId=="senseHatid")
{
v= "From Sense Hat";
}
return {payload:v}
Return value is always "From Sense Hat," but I am able to receive both the data in debug. I get the same result if I use msg.deviceType in the if else statement.
It looks like you are publishing all the data from the Raspberry Pi and the SenseHAT using the senseHatid.
Are you using Node-RED to publish the readings from the Raspberry Pi? If so ensure, that you are setting the msg.deviceType and msg.deviceId values for the outbound Watson IoT node to the Raspberry Pi gateway for the CPU temperature and the SenseHit device for the senseHat data.

Is it possible for one device to subscribe to MQTT events or commands from another device on IBM IoTF?

I am building an iOS app to control my Raspberry Pi over MQTT. I want to be able to send control commands from my iPhone to the Pi and have the Pi respond with a status update.
The Pi is running Node-RED and can both send and receive both events and commands to IBM IoT Foundation (verified from a Bluemix Node-RED application).
The iPhone Swift app is using https://cocoapods.org/pods/MQTTClient (Note - does not specifically list IBM IoT as a tested platform).
From the Swift app, I have successfully connected to IBM IoTF and sent events which the Pi receives. I have also successfully subscribed to command topics in the form "iot-2/cmd/streamStarted/fmt/json", but never receive a message. If I try to publish a command in the form "iot-2/cmd/startStream/fmt/json" or subscribe to events in the form "iot-2/evt/streamStarted/fmt/json" or "iot-2/type/myPi/id/<myPiID>/evt/streamStarted/fmt/json", the connection immediately closes.
The bottom line is that I need to get a status message from the Pi to the iPhone in some way. I don't really care if it is an event, a command or something else. I have been successful doing this with test.mosquitto.org, events but not IoT Foundation.
Only applications can send commands to a device. You can't send a command from one device to another. Is the iphone swift app connecting to IoT Foundation as an application or trying to connect as a device?