Using Mendix dashboard to control sensors by using a button

0
Hi I am currently a student who is doing an IOT project and I am currently facing some problems. I am to get sensor data from thingspeak and be able to read the sensor values in my dashboard created by Mendix and also be able to control the sensors ( such as light sensors to on/off the light and hydro sensors to control the water) from my dashboard.  What I have discovered during my research is that there is this microflow called “ REST api”. I am thinking that in order to read the data from thingspeak to Mendix, it would be better to create an JSON format in Mendix based on the READ api in thingspeak. Hence, I was thinking of doing the same thing for controlling the sensors ( sending a boolean value of 0 or 1 to thingspeak).  The method I am thinking of is by using the “ CALL REST Activity” only to get data from thingspeak and sending data from Mendix to thingspeak. The difference is that I set it to HTTP PUSH and the URL will be the READ API key given in thingspeak. Is this the correct way of doing it?    https://docs.mendix.com/howto/integration/publish-rest-service I also came across this article which talks about sending data outside Mendix but I am not entirely sure what this article is talking about. I sincerely hope that I would get some advices from the professionals so that I will be on the correct track. I am terribly sorry if it is hard to understand my question and thank you for taking your time to read this. I am using Mendix Studio Pro version 8.18.3 if that helps.
asked
3 answers
0

HI Andy,

In order to get your desired data you need to use the Call Rest activity in your microflow and set it to GET operation. Use this in combination with your read API key from ThingSpeak.

To control your sensor use the Call Rest activity and set it top POST. Use this one in combination with your write API key from ThingSpeak. 

Your documentation link is for publishing a rest service. This is not your usecase as you are consuming a rest service.

answered
0

Hi Sjors Schultz,

 

Thank you for your very fast response. I will try to attempt now.

 

 

answered
0

Hi. I managed to get the receiving of data from Thingspeak to Mendix thanks to your advice and https://academy.mendix.com/link/path/44/Importing-and-Exporting-Your-Data but I still have troubles sending data from Mendix to Thingspeak. My end goal for this part is that whenever a switch is pressed, a value of “1” or “0” will be sent to thingspeak.

 

May I know if the steps for sending data from Mendix to Thingspeak the same as receiving data? ( Like creating an import mapping from WRITE api in thingspeak and creating a JSON). What I have tried was to first create a JSON and an addition thing called “ Export Mapping”. I created this Export mapping because according to this link, it says that it is used to convert Mendix objects into XML or JSON format. https://docs.mendix.com/refguide/mapping-documents 

 

 

 

 

 

 

 

Here is my entities. Send_Data entity is the only entity I have created so far solely to send data from Mendix to Thingspeak. I associated it with System:User because I want it so that whenever a user logs in, it will show up to every account.

 

Here is my microflows: ( I am showing the URL link as well as I am not that sure that it is the correct format to type in)

 

I feel that I am on the wrong track and I really need some professional help. I have no knowledge of programming as well as IOT-related stuff so I am learning a lot of stuff all at once which results in getting myself confused even more.  I would really be grateful if there is an example that I could refer to. I am really sorry for asking a lengthy question. 

 

 

 

 

answered