I referenced the [Configure a Raspberry Pi and connect it to Watson IoT Platform]
In that, I am using Node-RED of Raspberry Pi 3 and send the data to IBM Cloud.
I use the Function Node for transform to Watson IoT Format,
So, I write the code in function node.
msg.payload={'d':{'temp':msg.payload.replace("temp=","").replace("'C\n","")}}
However, it has the result that represent {d:obeject}
I want to represent {"d":{"temp":"45.5"}}
Did I miss something?
I attached image file.
The Debug sidebar shows a structured, interactive, view of the message.
If you click on the {d: object } line it will expand to reveal its structure.
Related
I am a beginner with raspberry pi 4 and I would appreciate any help.
I am making a simple project in .net – basically I have a web APi service which should read raspberry Pi device sensor’s indications. I have read that the simplest communication between my Web APi service and the raspberry Pi sensors is setting up an MQTT broker to act as an IOT server
Have somebody tried this and is it a simple process. Also is this a simple code, should I write the commands in Python. I saw that most people use mosquito as it is easy to install on Pi.https://mosquitto.org/. In my web APi c# project I will use an MQTT library to send (publish) AND RECEIVE messages(the sensor indications) to that broker. The question is – would it be hard to send this sensor's information from the Raspberry to the broker with the sensor indications.
Thank you so much.
I think your question is fragmented:
What sensors are you reading?
Do you need mosquitto? Depending on what you want to do, frequency of calls, concerns about transport performance or payload size etc. You may or may not require an MQTT broker, in the case that you need one, you can build one in .Net with MQTTnet or similar.
You say you're starting out but you have or know how to build a .Net Web API, in that case I say stick to what you know and decide if you want to go the mosquitto route later.
If you have a .Net Web API, you can write python requests against your .Net Web API.
That's easy-peasy as python isn't hard to get started with.
If you want to stick to .Net and you are more comfortable with it, explore Mono or run VS Code https://www.hanselman.com/blog/HowToInstallVisualStudioCodeOnARaspberryPi4InMinutes.aspx and some have even loaded .Net Core.
At your own risk you can even explore experimental options like Windows 10 Arm and Windows IOT Core as options, then you should be able to run .Net apps on them.
In your case you definitely don't need mosquito/mqtt transport. The delay is long enough to just use your regular .Net Web API.
Combine the following tutorials:
https://pimylifeup.com/raspberry-pi-humidity-sensor-dht22/
https://www.w3schools.com/python/module_requests.asp
Ideally you want to post the data but for example sake here is a get request.
Python example:
x = requests.get('http://localhost:5000/api/raspberrypi?sensorId=1&temperature=22.5&humidity=34')
Your .Net Web Api Endpoint:
public async Task<IHttpActionResult> Get(int sensorId, double temperature, double humidity)
{
var timeStamp = DateTime.Now; //Date & Time of receiving reading.
// Your save code here
}
Note, I included a field for sensorId in case you have several sensors sharing the controller.
Im planning to create an android Raspberry Pi 3 using Lineage OS. My concern is the GSM module. Does Lineage OS can read the GSM Module (SIM900) in Raspberry Pi and detects it as a SIM Card? My goal is to send SMS using Lineage OS Raspberry Pi 3.
The high level view
connect the SIM900 module to the RPi using the serial connection
write a program to send AT commands to the SIM900 to send SMSes
setup a php script in a web server to receive SMS parameters and make it call the program from step 2.
Lower level view
You may want to read this blog to see how to connect your SOM900 to the RPi. There are actually many blogs like this one so if this one is not clear, just Google "Connecting SIM900 Raspberry"
To send SMS you need to send some so called Hayes AT commands to the modem. The Commands are defined in specification "3GPP TS 27.005", but basically you need to do the following (not tested...). This is adapted Python: I don't know the equivalent of serial module in php:
import serial
import time
modem=serial.Serial("/dev/<the serial device>", baudrate=9600, timeout=1.0)
modem.open()
modem.write("AT+CMGF=1\r")
time.sleep(0.5)
modem.write("AT+CMGS=\"<the desination mobile number>\"")
modem.write(";\r")
time.sleep(0.5)
modem.write(<the content of the SMS>")
time.sleep(0.2)
modem.write(chr(26)) # character Ctrl-Z meaning end of message
time.sleep(0.5)
However, if you want to send messages in a specific charset different from the default GSM alphabet, you'll need to need to do some coding (see here).
I believe the Web Server step shouldn't be an issue for you. You need 2 parameters for your script: the destination of the message and the message itself.
Hope this helps.
I am using a Watson IOT Output (wiotp out) in a Node-RED flow on my Raspberry PI and am having issues with the connection repeatedly disconnecting and then re-connecting.
Here is a screenshot of my Credentials Node and one of my IOT Out Node.
The connection is configured so that I can send messages to the cloud and successfully have them trigger a flow in my cloud Node-RED instance.
The problem I'm having is that when I attempt to send a string array as my payload, very items in the array actually make it through before the service disconnects. I am limited to around 3-5 strings at a time, which is frustrating because I am losing 195-197 of the 200 items I am trying to send to the IOT platform.
How can I keep a persistent connection and make sure my entire payload makes it through to the IOT service?
If you're seeing very frequent disconnects, it can often mean that you're inadvertently performing clientId stealing (i.e., two MQTT clients are fighting over the same clientId). You can confirm this by looking at the device connection logs in the device drilldown panel: you'll see evidence of log messages such as "The client ID was reused."
Ben
I understand that we can add IBMIoT nodes to node-red in bluemix and then read the data from the node and do any processing of the data as required by the use case. For this we need to give a device id to the node. Is it possible to create a flow where the device id is dynamic. Let's say I have 10000 sensors / devices. I want to read the data for each of these sensors in a mulitplexed fashion by changing the device id.
It is impossible to create 10000 device nodes. So, what is the best way to manage this number of sensors / devices?
For the In nodes, set the deviceId to All.
Then use the msg.deviceId property to figure out which deviceId it is. This can also be used to used with the IBM IoT Out node. When msg.deviceId is set on a message sent to the Out node, it will over-ride what is set in the node itself.
If it isn't working for you, please add your code.
We can tick All option (device Id) in IBM IoT node option pop up , which helps to connect all Registered devices with different deviceId to Single IBM IoT Node.
How can we direct a Amazon Echo intent to a private/internal https endpoint? Like a raspberry pi running nodeJS.
Using an "Echo Proxy" still requires to have the service accessible from internet (More on Echo Proxy: https://www.reddit.com/r/amazonecho/comments/3blkax/alexa_api_proxy_java/ )
Using "HUE Bridge Emulator" will help you fork the Alexa request to a private(internal only) https server. However, this setup limits usage of Alexa intents to "Turn on" or "Turn off" (and set dim level etc). (More on HUE Bridge Emulator: https://github.com/armzilla/amazon-echo-ha-bridge )
I would love to hear feedback on how can we work around this problem.
EDIT: I now have a stable, working setup of my Pi controlled by Amazon Echo. And this is how it is configured:
Setup AWS Lambda to handle incoming intents from Echo
On Lambda, map a "ACTION KEYWORD" for each intent/slot
On a matching intent/slot, post the ACTION KEYWORD to PubNub channel
Setup my Pi to SUBSCRIBE to PubNub channel for new messages
If Pi receives a matching ACTION KEYWORD on the channel, it triggers a function/script
This function/script in turn has the complete execution logic (example: Open garage door)
I'd love to hear feedback on this method and leaving the question open for others to post simpler/better way to achieve this
Another way is to use a service like dataplicity.com. This gives you a url to access your Pi. I use it with Node-RED to have multiple endpoints that I can access from anywhere for my Alexa Skills as well as my chatbots.
This is a relatively old question, but if you'd like to use Alexa to send commands to a local accessory and you don't mind a Bluetooth or BLE connection between the Pi and your Echo device, you might want to take a look at Alexa Gadgets Toolkit (AGT): https://developer.amazon.com/en-US/docs/alexa/alexa-gadgets-toolkit/understand-alexa-gadgets-toolkit.html
With AGT you can setup a Raspberry Pi as a gadget, which is a connected accessory, that you can control through custom directives from a custom skill. There is also support for the gadget to send events to the skill but only while the skill is running.
There are samples on GitHub that should help you turn a Raspberry Pi into an Alexa Gadget with minimal effort: https://github.com/alexa/Alexa-Gadgets-Raspberry-Pi-Samples
You might want to follow this tutorial: https://github.com/alexa/Alexa-Gadgets-Raspberry-Pi-Samples/tree/master/src/examples/color_cycler that has bi-directional communication capabilities between a gadget and a custom skill.