Smart home part 2: Driving relay through the cloud.

Please get familiar and try to make my first instructable where I show you how to log your house temperature into intel cloud using Edison. Please follow steps 2-3 of the above instructable to set up your edison and your Intel IoT Analytics Dashboard.

This time it took me few evenings to master this... in the meantime I had to overcome many difficulties... ok let's start...

Step 1: Assemble the Edison!

First you have to attach your Edison to Arduino dev board.

Guide it through mounting screws and press gently press it in place where you see white label.

Second - get base board from the Grove Starter Kit and put it in place on dev board.

At last - take one cable and Relay from the Grove Starter Kit and connect it together to DIGITAL I/O, in my case D2.

Step 2: Update iotkit-admin and pair your Edison with IoT cloud.

It is crucial you update iotkit-admin as current image comes with old version which doesn't support control function correctly. These steps took me lot of forum consulting, trying and failing but finally I got it right :-)

  • npm update -g iotkit-agent

  • iotkit-admin -V

    Should read "1.6.5" or higher

  • iotkit-admin test

    Should return with no errors

  • iotkit-admin move-data-directory ~/.data

    Saves your config files in ~/.data/

  • iotkit-admin device-id

    Should get "Device ID"

  • Mark device id and copy it.

  • Go to your IoT Analytics to My Devices panel and press "Add new device". Paste device id into fields ID and Gateway, give it some cool name and save. Now go to My Account panel, generate new activation code and make it visible.

  • Go back to Edison command prompt and type in "iotkit-admin activate YOURACTIVATIONCODE"(substitute your code of course).

  • iotkit-admin activate

  • iotkit-admin register power powerswitch.v1.0

  • iotkit-admin protocol mqtt
  • systemctl restart iotkit-agent

    Step 3: The hardest part... the CODE

    Please try to analyze it and understand what each line is doing, that is how you can learn the best.

    #include // include IoTkit.h to use the Intel IoT Kit
    #include // must be included to use IoTkit #include #include // create an object of the IoTkit class IoTkit iotkit; const int relayPin = 2; void setup() { Serial.begin(115200); // call begin on the IoTkit object before calling any other methods iotkit.begin(); delay(10500); pinMode(relayPin, OUTPUT); } void loop() { iotkit.receive(callback); delay(5000); } void callback(char* json) { Serial.println(json); aJsonObject* parsed = aJson.parse(json); if (&parsed == NULL) { // invalid or empty JSON // Serial.println("recieved invalid JSON"); // for troubleshooting return; //parsing JSON } aJsonObject* component = aJson.getObjectItem(parsed, "component"); aJsonObject* command = aJson.getObjectItem(parsed, "command"); aJsonObject* argv = aJson.getObjectItem(parsed, "argv"); aJsonObject* argvArray = argv->child; aJsonObject* name = argvArray->child; // name : on aJsonObject* value = name->next; // value: 1/0 if ((component != NULL)) { if (strcmp(component->valuestring, "power") == 0) { if ((command != NULL)) { if (strcmp(command->valuestring, "LED.v1.0") == 0 && strcmp(value->valuestring, "0") == 0) { Serial.println("Light Off!"); digitalWrite(relayPin, false); } if (strcmp(command->valuestring, "LED.v1.0") == 0 && strcmp(value->valuestring, "1") == 0) { Serial.println("Light on!"); digitalWrite(relayPin, true); } } } } }

    Step 4: The easy part, controlling relay through IoT Analytics Dashboard

    Smart home part 2: Driving relay through the cloud.

    If you did all the previous steps correctly you should be ready to control the relay through IoT Analytics Dashboard!

  • Go to Control module in IoT AD.
  • Select your device and Component.
  • Set parameter value to "1" and press "add action"
  • Press "Send" next to your newly created action.

    In few seconds you should hear your relay "click" and it's LED will start glowing.

    You can connect some device you want to control thorough cloud to this relay.

    HAVE FUN!

  •  
     

    Tag cloud

    make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel