text: from sense_emu import SenseHat
  from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
  import argparse
  import time
  import json
  wait_for = 1
  
  # Read in command-line parameters
  parser = argparse.ArgumentParser()
  parser.add_argument("-e", "--endpoint", action="store", required=True, dest="host", help="Your AWS IoT custom endpoint")
  parser.add_argument("-r", "--rootCA", action="store", required=True, dest="rootCAPath", help="Root CA file path")
  parser.add_argument("-c", "--cert", action="store", required=True, dest="certificatePath", help="Certificate file path")
  parser.add_argument("-k", "--key", action="store", required=True, dest="privateKeyPath", help="Private key file path")
  parser.add_argument("-p", "--port", action="store", dest="port", type=int, help="Port number override")
  parser.add_argument("-w", "--websocket", action="store_true", dest="useWebsocket", default=False,
                      help="Use MQTT over WebSocket")
  parser.add_argument("-id", "--clientId", action="store", dest="clientId", default="basicPubSub",
                      help="Targeted client id")
  parser.add_argument("-t", "--topic", action="store", dest="topic", default="sdk/test/Python", help="Targeted topic")
  
  args = parser.parse_args()
  host = args.host
  rootCAPath = args.rootCAPath
  certificatePath = args.certificatePath
  privateKeyPath = args.privateKeyPath
  port = args.port
  useWebsocket = args.useWebsocket
  clientId = args.clientId
  topic = args.topic
  
  if args.useWebsocket and args.certificatePath and args.privateKeyPath:
      parser.error("X.509 cert authentication and WebSocket are mutual exclusive. Please pick one.")
      exit(2)
  
  if not args.useWebsocket and (not args.certificatePath or not args.privateKeyPath):
      parser.error("Missing credentials for authentication.")
      exit(2)
  
  # Port defaults
  if args.useWebsocket and not args.port:  # When no port override for WebSocket, default to 443
      port = 443
  if not args.useWebsocket and not args.port:  # When no port override for non-WebSocket, default to 8883
      port = 8883
  
  # Init AWSIoTMQTTClient
  myAWSIoTMQTTClient = None
  if useWebsocket:
      myAWSIoTMQTTClient = AWSIoTMQTTClient(clientId, useWebsocket=True)
      myAWSIoTMQTTClient.configureEndpoint(host, port)
      myAWSIoTMQTTClient.configureCredentials(rootCAPath)
  else:
      myAWSIoTMQTTClient = AWSIoTMQTTClient(clientId)
      myAWSIoTMQTTClient.configureEndpoint(host, port)
      myAWSIoTMQTTClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath)
  
  # AWSIoTMQTTClient connection configuration
  myAWSIoTMQTTClient.configureAutoReconnectBackoffTime(1, 32, 20)
  myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1)  # Infinite offline Publish queueing
  myAWSIoTMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
  myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10)  # 10 sec
  myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec
  
  # Connect to AWS IoT
  myAWSIoTMQTTClient.connect()
  time.sleep(2)
  
  
  def send_to_aws(data):
      message = {}
      message['deviceID'] = "Ubuntu-Laptop"
      message['date_time'] = int(time.time())
      message['Humidity'] = data
  
      messageJson = json.dumps(message)
      try:
          myAWSIoTMQTTClient.publish(topic, messageJson, 1)
      except:
          print("erro")
      print('Published topic %s: %s\n' % (topic, messageJson))
  
  
  def sensor_hat():
      sense = SenseHat()
  
      last_humidity = 0
      while True:
          time.sleep(wait_for)
          humidity = int(sense.humidity)
          if humidity > last_humidity + 1 or humidity < last_humidity - 1:
              send_to_aws(humidity)
              last_humidity = humidity
  
  
  def main():
      print("Developed by Adilson Perinei - adilson@perinei.com")
      print("SenseHat Project: Send data to AWS IoT")
      sensor_hat()
  
  
  main()
  