How to publish plain text payload from AWS Lambda python function to IOT Core?

0

I want to publish the value 0 65432 0 192.168.2.1 502 5 1 6 338 0 to an IOT core topic from my lambda function. These are Modbus commands, that our modems can only interpret without surrounding quotes. However, IOT Core always receives the value including the quotes, which the modems cannot interpret. How do I publish this value without quotes as my IOT Core payload?

질문됨 4달 전131회 조회
1개 답변
0
수락된 답변

Hi. Are you sending 0 65432 0 192.168.2.1 502 5 1 6 338 0 as a string? I think that's what you mean. 37 bytes are sent, and 37 bytes received by subscribers. No characters added.

Lambda:

import boto3
import json

def lambda_handler(event, context):
    print('Hello')
    iot = boto3.client('iot')
    endpoint = iot.describe_endpoint(endpointType='iot:Data-ATS')['endpointAddress']
    print(f'{endpoint}')
    iot_data = boto3.client('iot-data', endpoint_url=f'https://{endpoint}')
    iot_data.publish(topic='repost', qos=0, payload='0 65432 0 192.168.2.1 502 5 1 6 338 0')

    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

And using mosquitto_sub as the subscriber because it reports the number of bytes:

@ubuntu:~/Desktop$ mosquitto_sub -h foobar-ats.iot.us-east-1.amazonaws.com -p 8883 -t repost --cert 8ffe5d98-certificate.pem.crt --key 8ffe5d98-private.pem.key --cafile AmazonRootCA1.pem -d
Client mosq-23ZjsfCHOnWUais1gn sending CONNECT
Client mosq-23ZjsfCHOnWUais1gn received CONNACK (0)
Client mosq-23ZjsfCHOnWUais1gn sending SUBSCRIBE (Mid: 1, Topic: repost, QoS: 0, Options: 0x00)
Client mosq-23ZjsfCHOnWUais1gn received SUBACK
Subscribed (mid: 1): 0
Client mosq-23ZjsfCHOnWUais1gn received PUBLISH (d0, q0, r0, m0, 'repost', ... (37 bytes))
0 65432 0 192.168.2.1 502 5 1 6 338 0

Perhaps I misunderstand your problem.

profile pictureAWS
전문가
Greg_B
답변함 4달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠