Related Articles

37 Comments

  1. Pingback: AWS Week in Review – November 2, 2015 | SMACBUZZ

  2. Pingback: AWS Week in Review – November 2, 2015 | wart1949

  3. 3

    M

    Really good article.
    Is code on github?

    Reply
    1. 3.1

      Onur SALK

      Thanks, I’ll upload them this weekend.

      Reply
      1. 3.1.1

        Anand Khatri

        Hello Onur,

        It’s really good example for AWS IoT with Raspberry Pi.
        Can you please share github link for this?

        Reply
        1. 3.1.1.1

          Onur SALK

          Hi,

          You can find the codes in my github account https://github.com/osalkk/aws_iot

          Reply
          1. 3.1.1.1.1

            Anand Khatri

            Thank you Onur.

  4. 4

    kklam888

    Hi,

    Could you also please provide some instructions on how you did the PHP page? Sorry, I’m a beginner here and not so clear on what exactly to do. Thanks.

    Reply
    1. 4.1

      Onur SALK

      You can view the html code using the webpage. The script that I call is
      script.php:

      < ?php $desired = $_POST["data"]; $count = $_POST["count"]; $command = exec("./iot/ledon.sh $desired $count"); echo $command; ?>

      and the ledon.sh is:

      #!/bin/bash
      cd /var/www/wekanban.com/iot
      state=$1
      count=$2
      echo $state
      /usr/bin/curl -H “Content-Type: application/json” -X POST -d ‘{“state”:{“desired”:{“led”:”‘$state'”,”count”:”‘$count'”}}}’ -k –cert ./my-certificate.pem.crt –key ./my-private.pem.key “https://url.iot.eu-west-1.amazonaws.com:8443/things/Raspberry-pi/shadow”

      Reply
      1. 4.1.1

        hacchu

        I am able to get the shadow state updated by the terminal via shell script .
        When i run the shell script with “on” as parameter its updating in the shadow state.
        But when i run the python script …..
        root@raspberrypi:~# ./aws_subscribe.py
        Connected with result code 0
        and also in aws iot home i am getting out of sync error
        I am not able to get what is the problem. thanks in advance

        Reply
  5. 5

    Marc Viñes

    Hi Onur,
    Great article! I have reproduced your code, and nearly got it working. As you did, I also use the same certificates for both: in the Raspberry and in the machine where you run the ledon script. I have done the same, and the certificates on the Raspberry work perfect allowing the device to connect to aws IoT, but i get an error running the ledon script: SSL routines:SSL3_READ_BYTES:sslv3 alert bad certificate. Do you have any idea why it might be happening?

    Anyway, thanks for “opening my eyes” to the possibilities of the IoS.

    Marc

    Reply
    1. 5.1

      Onur SALK

      Hi Marc,

      First of all thanks for your good comment and I’m glad you loved it. Can you share your ledon script?

      Reply
      1. 5.1.1

        Marc Viñes

        In fact, after investigating the issue, i was able to solve it. The problem was related to the curl command in ledon.sh. I had to combine certificate.pem.crt and private.pem.key into one single file (thus avoiding the –key parameter). Doing this little change, it worked like a charm.

        Thanks for your help!

        Marc

        Reply
        1. 5.1.1.1

          Onur SALK

          Cool! You are welcome!

          Reply
  6. 6

    Chris

    I agree with the previous comments… this is an awesome step-by-step to get started with IoT and AWS. I’ve bookmarked it for the future when I decide to build one for myself. Thanks!

    Reply
    1. 6.1

      Onur SALK

      Thanks Chris, I’m glad you liked it!

      Reply
  7. 7

    James

    Thanks a million Onur for this step by step guide. I am trying to publish a message to AWS IoT. I am trying to follow your steps but nothing appears on AWS. I have also checked your git repo files but still nothing. Please excuse me, I am rather new to python. But I did follow your guide and I get rc=0 successful…but I see no messages on AWS. I have also subscribed to the AWS IoT MQTT for the topic, but also no messages appeared. Earlier I found I didn’t have the right Python version but that is now fixed. 2.7.11

    Reply
    1. 7.1

      Onur SALK

      Hi James,

      I’ll reply you via your email.

      Reply
      1. 7.1.1

        sania

        Yes, same happened with me as well. I tried all the possibilities to get the message on aws but nothing worked. It is just showing rc=0 successfull.

        Reply
        1. 7.1.1.1

          Onur SALK

          I replied in comments.

          Reply
  8. 8

    firman

    hi there..im currently doing a poject to collect air quality temperature..is there anyway I can connect my raspberrypi straight to dynamodb? or I need to set a aws iot first then I can connect to dynamodb?

    Reply
    1. 8.1

      Onur SALK

      Yes it is better to use the IoT service and then you can insert your data to dynamodb.

      Reply
      1. 8.1.1

        firman

        do you know what is the code for python to store data in iot service and to dynamodb

        Reply
        1. 8.1.1.1

          Onur SALK

          You don’t need to code it, you can configure it on IoT console.

          Reply
  9. 9

    Sania

    Hi Onur,

    It’s an amazing article. Please help me since i’m a beginner. I’m trying to send simple message from raspberry pi to aws iot but i’m getting little confused in how are we adding the topic and for one way communication that is from raspberry pi to aws iot, we just need to publish. right??. And, yes same thing is happening with me as with James.

    Reply
    1. 9.1

      Onur SALK

      Hi Sania,

      Thanks. can you try this

      #!/usr/bin/python2.7
      
      
      import paho.mqtt.client as mqtt
      import ssl
      import json,time
      
      
      
      def on_connect(client, userdata, flags, rc):
          print ("Subscriber Connection status code: "+str(rc))
      
      def on_publish(client, userdata, mid):
          print(client, userdata, mid)
      
      
      #Connect to AWS IoT
      print("starting aws client")
      awsclient = mqtt.Client(client_id="rasp1-test",protocol=mqtt.MQTTv311)
      awsclient.on_connect = on_connect
      awsclient.on_publish = on_publish
      awsclient.tls_set("./root-CA.pem",certfile="./c9aa9ef139-certificate.pem.crt",keyfile="./c9aa9ef139-private.pem.key",tls_version=ssl.PROTOCOL_SSLv23,ciphers=None)
      awsclient.tls_insecure_set(True)
      awsclient.connect("XXXXXXX.iot.eu-west-1.amazonaws.com", 8883, 60)
      awsclient.loop_start()
      
      rc=0
      while rc == 0:
         data={}
         data['temp']='64'
         data['humid']='65'
         print(data)
         payload = json.dumps(data)
         print("Payload: " + payload)
         awsclient.publish("Rasp/data", payload, qos=1)
         time.sleep(10)
      
      print('rc: ' +str(rc))
      
      Reply
  10. 10

    Akram

    Great work !!

    Please tell me how can I know the client id to call the Client constructor??

    Reply
    1. 10.1

      Onur SALK

      We define the client id as below. Do you mean something else?

      client = mqtt.Client(client_id=”rasp1″,protocol=mqtt.MQTTv311)

      Reply
      1. 10.1.1

        akramshaik541

        Yes ! what is that client id.Is it a thing name?

        Reply
        1. 10.1.1.1

          Onur SALK

          You can read about mqtt client here

          Reply
  11. 11

    John

    Hi Onur,

    while executing this I am getting the following error:

    ssl.SSLError:[SSL:SSLV3_ALERT_CERTIFICATE_UNKNOWN sslv3 alert ccertificate unknown]

    in the tls_set().Please tell me whats wrong done with the code

    Reply
    1. 11.1

      Onur SALK

      Do you use the same code?

      Reply
      1. 11.1.1

        John

        Yes ! I used similar type of code but getting some SSL Error.. in the tls_set(),connect() method. I am getting Authorization error

        Reply
        1. 11.1.1.1

          Onur SALK

          Can you share your code to my email address, salk.onur@gmail.com?

          Reply
  12. 12

    Praveen

    How , publishing data to Rasp/data topic is updating the thing topic $aws/things/Raspberry-pi/shadow/update/accepted ?, how AwS IOT will know what is Rasp/Data?, is it not required that publisher and subscriber point to same topic?

    Reply
    1. 12.1

      Onur SALK

      I replied you via email.

      Reply
  13. Pingback: Test LED & Raspberry Pi Connection Week 3 Blog; 7 – Third year Raspberry Pi IoT demostration

Leave a Reply