Mail via IoT on AWS (mosquitto_pub)

Asked 2 months ago, Updated 2 months ago, 1 views

Raspy GPIO (16) and
when the switch is on I'm thinking of sending an email via AWS IoT.
In the Python program below, the lines mosquitto_pub to show "SyntaxError: invalid syntax".
It may be elementary, but I would appreciate it if you could point out the defect.
Incidentally, if you enter the same sentence (mosquitto_pub...-m'Hello, World') directly in the raspy, the email will be sent successfully.

# coding: utf-8

# To Import a module
import RPi.GPIO as GPIO
import time

#   by a GPIO (general purpose input output port number designated by a GPIO

#   GPIO pin 6 as an input mode
GPIO.setup(16, GPIO.IN)

num = 0
while num < 10:
    Sprint   (GPI inputVar (16 )) G PIO 16 input state of the pin #
    if GPIO.input(16) == 1 :
        mosquitto_pub --cafile rootCA.pem --cert ~~~~~~~-certificate.pem.crt --key ~~~~~~~-private.pem.key -h -p 8883 -q 1 -d -t topic/sns -m 'Hello, World'
    num = num +1

# Resetting the GPIO Pin


2022-09-30 11:21

1 Answers

I confuse Python's program with the command that I type into the shell.

mosquitto_pub --cafile rootCA.pem --cert~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

where mosquitto_pub is the command of the shell to run with various optional arguments, such as --cafilerootCA.pem.It doesn't work well even if I type it in as Python's program.

To move an external executable from Python, for example, you can use the standard library subprocess module.The following are possible writing methods for Python 3.5 and later:

import subprocess["mosquitto_pub", "--cafile", "rootCA.pem", (omitted)])

Python versions 3.5 and older have a way to use

import subprocess"mosquitto_pub", "--cafile", "rootCA.pem", (omitted)])

2022-09-30 11:21

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.