Ewon TechForum
Providing technical solutions to technical requests


MQTT Script to connect AWS IOT (Amazon)
simon Offline
eWON Support
#1
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 :
.pdf   HMS eWON Flexy integration to AWS.pdf (Size: 617,04 KB / Downloads: 236)
Here is the root CA that you need to upload into your Flexy (you need to first unzip it) :
.zip   root-CA.zip (Size: 1,24 KB / Downloads: 101)

Bye

Simon
Reply

jvondrus Offline
Junior Member
#2
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.
Reply

simon Offline
eWON Support
#3
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) ?
Reply

Quantum Offline
Junior Member
#4
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.
Reply

simon Offline
eWON Support
#5
Please check this post as well :
https://techforum.ewon.biz/thread-559.html
Reply

sego_yunior Offline
Junior Member
#6
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)
Reply

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

sego_yunior Offline
Junior Member
#8
(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!
Reply

simon Offline
eWON Support
#9
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
Reply

LionelGos Offline
Junior Member
#10
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!
Reply

simon Offline
eWON Support
#11
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
Reply

LionelGos Offline
Junior Member
#12
(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?
Reply

simon Offline
eWON Support
#13
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
Reply

LionelGos Offline
Junior Member
#14
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
Reply

simon Offline
eWON Support
#15
Lionel,

You should try this example instead : https://techforum.ewon.biz/thread-559-po...ml#pid2874

Simon
Reply



Possibly Related Threads…
9 hours ago
Last Post: simon
09-03-2020, 02:29 PM
Last Post: simon
06-03-2020, 06:39 PM
Last Post: simon
24-01-2020, 09:45 PM
Last Post: tedsch
07-01-2020, 03:34 PM
Last Post: simon
02-12-2019, 11:25 PM
Last Post: simon
30-10-2019, 10:02 PM
Last Post: Nikolai
03-09-2019, 02:08 PM
Last Post: simon
  MQTT hangs Started by Tecmafra
1 Replies - 628 Views
26-07-2019, 10:12 AM
Last Post: SivakumarRn
23-07-2019, 05:31 PM
Last Post: simon



Users browsing this thread:
1 Guest(s)



Theme © Ewon 2019 - Forum software by © MyBB - Cookie policy