Switch to desktop version  
MQTT Script to connect AWS IOT (Amazon) - Printable Version

+- Ewon Technical Forum (https://techforum.ewon.biz)
+-- Forum: Development (https://techforum.ewon.biz/forum-50.html)
+--- Forum: BASIC Script (https://techforum.ewon.biz/forum-52.html)
+--- Thread: MQTT Script to connect AWS IOT (Amazon) (/thread-474.html)

Pages: 1 2


MQTT Script to connect AWS IOT (Amazon) - simon - 20-12-2017

Hi Guys,

Here is an example of BASIC script to connect AWS IOT plateform through MQTT :


Code:
MQTT "open", "ewon_flexy", "data.iot.eu-central-1.amazonaws.com"
MQTT "setparam", "port", "8883"
MQTT "setparam", "log", "1"
MQTT "setparam", "keepalive", "30"
MQTT "setparam", "cafile","/usr/aws/root-CA.crt"
MQTT "setparam", "certfile","/usr/aws/ewon_flexy.cert.pem"
MQTT "setparam", "keyfile","/usr/aws/ewon_flexy.private.key"
MQTT "connect"

MQTT "subscribe", "ewon_read", 0
ONMQTT "GOTO MqttRead"

Onchange "Tag1", "GOTO PublishMqtt"
Onchange "Tag2", "GOTO PublishMqtt"

END

MqttRead:  
  r%=Mqtt "Read"
  If (r%>0) Then
     MsgTopic$= Mqtt "MsgTopic"
     MsgData$ = Mqtt "MsgData"
     Print "MQTT Rx:" +MsgTopic$+" "+MsgData$
     IF MsgData$ = "TEST" THEN D0@ = 1
     Goto MqttRead
  Endif
END

PublishMqtt:
   AWSMQTTMsg$ = '{"tag1":' + STR$(Tag1@) + ', "tag2":' + STR$(Tag2@) + '}'
   Topic$ = "ewon_data"
    
   STATUS% = MQTT("STATUS")
   
   //Is Connected
   If (STATUS% = 5) Then
     Print "PUBLISH: " + AWSMQTTMsg$  
     MQTT "PUBLISH", Topic$, AWSMQTTMsg$, 0, 0
   Else
     Print "Not connected"
   Endif
END


This example allows you to publish the Tag values when they changes.  We use two Tags named "tag1" and "tag2"
It also allows you also to receive the message sent from the AWS plateforms (See the command ONMQTT).
For more details about the BASIC MQTT function, refer to the Programming Reference Guide (https://developer.ewon.biz/system/files_...download=1), page 58.

Here is a document that describe hwo to build this demo step by step :
  HMS eWON Flexy integration to AWS.pdf (Size: 617,04 KB / Downloads: 370)
Here is the root CA that you need to upload into your Flexy (you need to first unzip it) :
  root-CA.zip (Size: 1,24 KB / Downloads: 168)

Bye

Simon


RE: MQTT Script to connect AWS IOT (Amazon) - jvondrus - 07-03-2018

Hello SImon,
I'm trying to secure my MQTT connection, I have certification files from "letsencrypt.org", which works perfect on my server, but eWON cannot connect.

How about "root-CA.crt", its same for all eWON and connection or I have to make my own?

Thank you.


RE: MQTT Script to connect AWS IOT (Amazon) - simon - 07-03-2018

No, the root-CA is only for AWS.

It is difficult to help you without knowing the setup of your server.
What do you use as MQTT broker ?
How did you set it up ?
Have you setup just a CA certifcate for the MQTT server authentication or a CA, client cert and a client Key (like for Amazon) ?


RE: MQTT Script to connect AWS IOT (Amazon) - Quantum - 03-05-2018

I tried to set up Flexy with AWS IoT and created the thing and the certificates. Problem is it only gives me 3 values, public key, private key and CA certificate. I am not sure what is this start.sh file and how I can generate one. Can you please help.


RE: MQTT Script to connect AWS IOT (Amazon) - simon - 03-05-2018

Please check this post as well :
https://techforum.ewon.biz/thread-559.html


RE: MQTT Script to connect AWS IOT (Amazon) - sego_yunior - 09-05-2018

Hi,

I want to connect to a MQTT (ignition by TLS) server and this server send me a certificate -> "root.ca.pem" but I do not know where is the /usr/

My question is: Where copy the file "root.ca.pem" into eWON flexy 205? (Where is folder usr)


RE: MQTT Script to connect AWS IOT (Amazon) - simon - 11-05-2018

Just connect the Flexy using your favorite FTP client (for example, https://filezilla-project.org/) and send the certificate to the usr directory.


RE: MQTT Script to connect AWS IOT (Amazon) - sego_yunior - 14-05-2018

(11-05-2018, 07:34 PM)Simon Wrote: Just connect the Flexy using your favorite FTP client (for example, https://filezilla-project.org/) and send the certificate to the usr directory.

Hi Simon,

Thanks for your answer, I have access to FTP by FileZilla and I have sent the certificate to the usr directory, and I have the next code

MQTT "OPEN", SerNum$ , "xxx.xxx.xxx.xxx"

MQTT "setparam", "port", "8883"

MQTT "setparam", "username", "admin"
MQTT "setparam", "password", "changeme"

MQTT "setparam", "cafile", "/usr/Ignition/root.ca.pem"

MQTT "CONNECT"

TSET 1,5
ONTIMER 1, "GOTO T1"
END

T1:
ConnStatus% = MQTT "STATUS"
Print "state: " ConnStatus%


The result is --> state: 3, so eWON is trying to connect but it never gets it.

How can I get information about the problem?  

Thanks!


RE: MQTT Script to connect AWS IOT (Amazon) - simon - 13-06-2018

Hi,

Sorry for the late answer... I guess this is still not fixed ?
Can you indicate what Ignition version/MQTT module you are using ? I would like to test it here...

Thx

Simon


RE: MQTT Script to connect AWS IOT (Amazon) - LionelGos - 26-11-2019

Hi Simon,

I'm trying to  use your script to establish a connection between an ewon flexy205 and AWS IOT.
I tried to connect via FTP to the flexy to push in /usr directory the amazon "credentials" but the connection doesn't work (I use Winscp as a FTP client).
What is the IP address I need to use to connect by FTP?

As I was not able to connect via FTP to push the files, I tried to write manually in the BASIC code the private key and PEM certificate as you did with  the CA certificate in this example : https://techforum.ewon.biz/thread-559.html
But it does not work, in the console it says 'disconnected', the MQTT connection status is '3'.

How can I connect via FTP to the flexy205? Maybe being able to upload the amzon certificates will solve my connection issue.

Thanks in advance!


RE: MQTT Script to connect AWS IOT (Amazon) - simon - 26-11-2019

Lionel,

That is strange indeed. You can normally connect the Ewon FTP server with any FTP client through any IP interfaces (LAN, VPN or WAN - If unprotected).
I personally use Filezilla as a FTP client.

Simon


RE: MQTT Script to connect AWS IOT (Amazon) - LionelGos - 26-11-2019

(26-11-2019, 02:22 PM)simon Wrote: Lionel,

That is strange indeed.  You can normally connect the Ewon FTP server with any FTP client through any IP interfaces (LAN, VPN or WAN - If unprotected).
I personally use Filezilla as a FTP client.

Simon

I was trying using the WAN IP, I tried connecting to the LAN port and tried to access via the LAN address (10.0.0.1). But I have an error : "Impossible to reach the host" when I try a ping test or when I try to connect with WinSCP.

Any idea why it does not work properly?


RE: MQTT Script to connect AWS IOT (Amazon) - simon - 26-11-2019

I am pretty sure it is a pure IP connection issue.
My advise is you try via the LAN, that's the easiest. Make sure your PC LAN is well in the same subnet. If you can access the Flexy webpages, you should then be able to access the FTP.

Simon


RE: MQTT Script to connect AWS IOT (Amazon) - LionelGos - 26-11-2019

Hi Simon,

Thanks for your answrer, to be able to connect to FTP I had to use the IP adress of the Flexy interface (connected by LAN).

I tried again to execute the code above (adapted the name of the things, uploaded the certificates, ... as described in the pdf), but I have the message "Not connected".
The Ewon can't establish the connection with AWS (MQTT status = 3 ). I also tried to send a message from AWS to eWON but the eWon does not receive anything.

What can I do to correct this issue?

Thanks in advance!

Lionel


RE: MQTT Script to connect AWS IOT (Amazon) - simon - 27-11-2019

Lionel,

You should try this example instead : https://techforum.ewon.biz/thread-559-post-2874.html#pid2874

Simon