Interfacing Arduino or Raspberry Pi to Zipabox / Zipatile

Alberto Macias shared this question 7 years ago
Answered

Hello community,


I have a couple projects at home to automate and integrate with Zipato controllers but there is no commercial interface that I can buy so, I have decided to remember my electronic skills I had when I was in university and create my own device, however looks like raspberry pi and arduino are the coolest kids on the neighborhood and doing some research I can imagine why. I really don't have experience with linux so for me arduino would be more familiar, but also looking into all the stuff they got available could be a difficult decision to make.


I want to ask your opinion and share your experience with any of these devices and which way would be more easy, reliable and deeply integrated, so far these are my options;

1. Arduino YUN using HTTP requests.

2. Arduino ONE with Wifi shield using HTTP requests.

3. Arduino ONE with Xbee Wifi shield using HTTP requests (looks like Xbee has their own online automation platform)

4. Arduino ONE with Xbee Zigbee shield, using Zigbee as comm protocol. Not sure if these devices will be compatible with Zipabox Zigbee expansion module.

5. Raspberry Pi using HTTP requests.


I just bought a couple books and trying to decide wether to go with arduino (and which comm protocol) or Raspberry. I know a few people have integrated raspberries so any light you can shed will be greatly appreciated.

Replies (9)

photo
1

Although it is overkill, I prefer the Raspberry Pi using Python and Flask. Currently, I am using my Pi to control my garage. It has garage door open/close sensors, it can open/close the doors, and I am working to integrate the PiCamera. I am getting ready to get a second Pi to use in my main house to interface between my legacy X10 devices and Zipato. I already have the X10 interface, but want to move it off my main server.

photo
1

Vernon,


Thanks for your input. Do you have any reference that you can share, I have never worked with a Pi and hardly ever used a Linux PC, also python is not a programming languaje I know, I will appreciate any guidance, thank you.

photo
photo
1

Alberto, have a look: https://z-uno.z-wave.me

photo
1

Thanks Pedro, I did look at those but unfortunately I cannot get those on US frecuency yet, so it is not an option.

photo
photo
1

I use the combi arduino nano and fibaro universal sensor a number of projects.

photo
1

Sounds interesting however I already bought the YUN so I want to test with HTTP and then with MQTT when zipato releases the interfase. Thank you.

photo
photo
2

I think the coolest kid these days are NodeMCU enabled devices. They cost next to nothing and have on-board Wi-Fi. You can program It with the Arduino IDE. To keep It kewl you should​ use MQTT and hope for Zipato MQTT support before you finish programming it 😉

The second coolest kid has to be the new Raspberry Pi Zero, now with Wi-Fi and bluetooth. Linux can be a pain in the ***, but usually you can find all the help you need online.

photo
1

Hello community,

So, I have spent some free time developing my new "interfaces" using arduino, I have managed to control all sensors to my Arduinos (ultrasonic for water level, relays, current sensors, gas sensors, LCD, 433 Mhz RF and more) the problem I'm having is communicating my Arduino YUN to Zipato Virtual meters, I have spent several hours reasearching how to perform HTTP GET/POST requests using the YUN but I haven't managed to communicate it succesfully with Zipato.

I'm writing this to see if some of the IT guys around here can help me with this, I know very little about HTTP requests. I have seen many ways (libraries) on the internet of guys uploading data to web servers but most of the requests are very different, Zipato ones seem very simple in comparison to these, no headers, no body, just URL... this is the only piece of the puzzle left so I can integrate these interfaces to zipato.

BTW Z-uno is now available on US frecuency, however for some of my solutions Z-wave range is not optimal and I really want to integrate these through WIFI, if anyone has some experience with Arduino YUN or Arduino Uno with Xbee S6B wifi I would really appreciate some help, I will share my Arduino code to see if someone can give me some adavices or help, thank you.

PS.- I have asked for help on Arduino forum but doesn't seem to be very helpful yet.

photo
1

These are a few attempts using Arduino YUN, I have replaced my serial and API numbers for obvious reasons.

#include "Bridge.h"

#include "HttpClient.h"

//Zipato Settings

String ZipatoAPI = "https://my.zipato.com/zipato-web/remoting/attribute/";;

String MySerial = "MyZipatoSerial";

String MyAPIkey = "MyAPIkey";

String ValueString="value15=150";

const int PostInterval = 15000;

// Variable Setup

long lastConnectionTime = 0;

void setup()

{

pinMode(LED_BUILTIN, OUTPUT);

Bridge.begin();

Serial.begin(9600);

}

void loop(){

delay (1000);

digitalWrite(LED_BUILTIN,HIGH);

HTTP_PostZipato1(ZipatoAPI,MySerial,MyAPIkey,ValueString);

delay(2000);

HTTP_PostZipato2(ZipatoAPI,MySerial,MyAPIkey,ValueString);

delay(2000);

HTTP_PostZipato3(ZipatoAPI,MySerial,MyAPIkey,ValueString);

;

delay(PostInterval);

digitalWrite(LED_BUILTIN,LOW);

}

void HTTP_PostZipato(String ZipatoAPI, String MySerial, String MyAPIkey, String ValueString)

{

//https://my.zipato.com/zipato-web/remoting/attribute/set?serial=MyZipatoSerial&apiKey=MyAPIkey&value15=150

HttpClient client;

String talkBackCommand;

char Response;

String URL = ZipatoAPI + "set?serial=" + MySerial + "&apiKey=" + MyAPIkey + ValueString;

client.get(URL);

Serial.println(URL);

while (client.available()) {

Response = client.read();

talkBackCommand += Response; // talkBackCommand = talkBackCommand + CharIn

Serial.println(talkBackCommand);

}

}

void HTTP_PostZipato2(String ZipatoAPI, String MySerial, String MyAPIkey, String ValueString)

{

String URL = ZipatoAPI + "set?serial=" + MySerial + "&apiKey=" + MyAPIkey + ValueString;

Process p;

p.runShellCommand(URL);

Serial.println(URL);

while(p.running());

// Read command output.

while (p.available()) {

int result = p.parseInt();

Serial.println(result);

}

}

void HTTP_PostZipato3(String ZipatoAPI, String MySerial, String MyAPIkey, String ValueString)

{

//POST https://my.zipato.com/zipato-web/remoting/attribute/set?value15=150&ep=MySerial&serial=MyZipatoSerial&apiKey=MyAPI

HttpClient client;

String talkBackCommand;

char Response;

String URL = "POST https://my.zipato.com/zipato-web/remoting/attribute/set?value15=150&ep=MySerial&serial=MyZipatoSerial&apiKey=MyAPI";;

client.get(URL);

Serial.println(URL);

while (client.available()) {

Response = client.read();

talkBackCommand += Response; // talkBackCommand = talkBackCommand + CharIn

Serial.println(talkBackCommand);

}

}

photo
2

Hello all in case someone is attempting to do the same I would like to give you an update on this, I finally managed to communicate my Arduino YUN to my Zipabox, replace "MYSERIAL", "MYAPIKEY" and "MYEP" for your information and you will be succesfully sending one HTTP post to write a random value on a virtual meter. Open you serial monitor to make it work, this is my first succesfull test, I'm currently working on a more advanced interface to integrate all the sensors I want to upload and receive all commands from Zipato. Will post my finished project.


  1. #include <Bridge.h>
  2. #include <BridgeHttpClient.h>
  3. BridgeHttpClient client;
  4. // Define Constants
  5. const String ZboxURL="https://my.zipato.com/zipato-web/remoting/attribute/";
  6. const String ZboxSerial="MYSERIAL";
  7. const String ZboxApiKey="MYAPIKEY";
  8. const String ZboxEp="MYEP";
  9. const String ZboxValue="value15";
  10. //Define Variables
  11. String ZipatoPostURL;
  12. int ValueOut;
  13. void setup() {
  14. pinMode(LED_BUILTIN, OUTPUT);
  15. digitalWrite(LED_BUILTIN, LOW);
  16. Bridge.begin(); // Initialize Bridge
  17. digitalWrite(LED_BUILTIN, HIGH);
  18. SerialUSB.begin(9600);
  19. while (!SerialUSB); // wait for a serial connection
  20. ValueOut=78; //Generate Random Value
  21. char * ZipatoPostChar=ZipatoBuildPost(ZboxURL,ZboxSerial,ZboxApiKey,ZboxEp,ZboxValue,ValueOut); //Build Zipato URL using ZipatoBuildPost function
  22. SerialUSB.println(ZipatoPostChar); //DO NOT REMOVE, FOR SOME REASON IT DOES NOT BUILD THE CHAR IF REMOVED
  23. ZipatoAsyncPost(ZipatoPostChar); //SEND ZIPATO ASYNC POST
  24. SerialUSB.print("Sending request");
  25. }
  26. void loop() {
  27. if (client.finished()) {
  28. SerialUSB.println();
  29. SerialUSB.println("Response Body:");
  30. while (client.available() > 0) {
  31. char c = client.read();
  32. SerialUSB.print(c);
  33. }
  34. SerialUSB.print(" Response Code: ");
  35. SerialUSB.println(client.getResponseCode());
  36. while (1) {} // stop
  37. } else {
  38. // not finished yet, wait and retry
  39. SerialUSB.print(".");
  40. delay(100);
  41. }
  42. }
  43. //BUILD ZIPATO STRING FUNCTION
  44. char * ZipatoBuildPost(String Zurl, String Zserial, String Zapi, String Zep, String Zvalue,int MtrVal){
  45. String result;
  46. result=Zurl+"set?serial="+Zserial+"&apiKey="+Zapi+"&ep="+Zep+"&"+Zvalue+"=";
  47. result += MtrVal;
  48. int str_len = result.length()+1; //Plus 1 for null terminator
  49. char resultchar[200];
  50. result.toCharArray(resultchar,str_len);
  51. return resultchar;
  52. }
  53. //ZIPATO ASYNC POST FUNCTION
  54. void ZipatoAsyncPost(char * JSONpost){
  55. //client.addHeader("Accept: application/json");
  56. //client.addHeader("Content-Type: application/json");
  57. client.enableInsecure(); // Using HTTPS and peer cert. will not be able to auth.
  58. client.postAsync(JSONpost, "");
  59. }

photo
2

This is my most up to date working example, much more polished, put together in one function and all commented out. In case someone wants to give it a try.


  1. /***************************************************************************
  2. *FN_zipatoasyncpost
  3. *This is a FUNCTION that assembles and sends HTTP Asynchronous POST to Zipato
  4. *servers to write values to Virtual Meters.
  5. *Each zipato Virtual Meter has 16 values.
  6. ***************************************************************************/
  7. #include <Bridge.h> //Required for communication between arduino and YUN
  8. #include <BridgeHttpClient.h> //Custom library to make JSON HTTP requests
  9. BridgeHttpClient zipaclient; //Declare HTTP client
  10. //Define Constants
  11. const long postdel=60000; //Asynchronous delay for post requests
  12. // Define Variables for Zipato
  13. String ZboxSerial="MYSERIAL"; //Zipato Controller Serial, this changes if controller changes.
  14. String ZboxApiKey="MYAPI"; //Zipato API Key, this changes if virtual device changes.
  15. String ZboxEp="MYEP"; //Zipato EP Key, this changes if virtual device changes.
  16. String ZboxValue="value1"; //Zipato identificator for Virtual Meter value to be written, this changes as required.
  17. //Timer Variables
  18. long postMillis=0; //Declare Timer variables for multitask delays
  19. //Declare Process Variables
  20. String ZipatoPostURL; //String to store assembled Zipato POST URL
  21. int ValueOut; //Value to send
  22. int Response; //Response code from Zipato Server
  23. /***************************************************************************
  24. * SETUP ROUTINE - Runs only once
  25. ****************************************************************************/
  26. void setup() {
  27. Bridge.begin(); // Initialize Bridge
  28. SerialUSB.begin(9600); // Start serial comm
  29. while (!SerialUSB); // Wait from serial connection from workstation
  30. delay (10000); //Wait for YUN to connect to wifi
  31. Response = FN_zipatojsonpost(ZboxSerial,ZboxApiKey,ZboxEp,ZboxValue,ValueOut,false); //Make POST request to Zipato and store response after boot
  32. SerialUSB.println(Response); //Print Response
  33. }
  34. /***************************************************************************
  35. * LOOP ROUTINE - This routine runs continuosly
  36. ****************************************************************************/
  37. void loop() {
  38. unsigned long curMillis = millis(); //define variable for timekeeping
  39. //IF TIME TO MAKE A POST REQUEST THEN JUMP
  40. if(curMillis - postMillis >= postdel) {
  41. postMillis = curMillis; //Update time
  42. ValueOut = random(0,999); //Generate Random Value to send to Zipato
  43. Response = FN_zipatojsonpost(ZboxSerial,ZboxApiKey,ZboxEp,ZboxValue,ValueOut,false); //Make POST request to Zipato and store response
  44. SerialUSB.println(Response); //Print Response
  45. }
  46. }
  47. /***************************************************************************
  48. *FN_zipatoasyncpost
  49. *This is a FUNCTION that assembles and sends HTTP Asynchronous POST to Zipato
  50. *servers to write values to Virtual Meters.
  51. *Each zipato Virtual Meter has 16 values.
  52. *RETURNS; Integer with Response Code
  53. *INPUTS;
  54. * String Zserial - Serial number for Zipato Controller
  55. * String Zapi - API Key from Virtual Meter
  56. * String Zep - EP Key from Virtual Meter
  57. * String Zvalue - Virtual Meter value placeholder name
  58. * int Val - Value to be writen into placeholder
  59. * boolean PrintSerial - If this value is TRUE this function will print more
  60. * information about Zipato response (debug).
  61. ***************************************************************************/
  62. int FN_zipatojsonpost(String Zserial, String Zapi, String Zep, String Zvalue,int Val, boolean PrintSerial){
  63. BridgeHttpClient zipatoclient; //Declare Client
  64. //Declare Zipato Constants
  65. const String Zurl="https://my.zipato.com/zipato-web/remoting/attribute/"; //Define Zipato basic URL, this does not change
  66. //Declare Variables
  67. String URL; //String to hold complete URL
  68. int str_len; //Integer to hold lenght of URL
  69. char URLchar[200]; //Char array to hold URL
  70. int retries=0; //Integer to hold timeout timer
  71. int respcode; //Integer to hold response code from Zipato
  72. URL = Zurl+"set?serial="+Zserial+"&apiKey="+Zapi+"&ep="+Zep+"&"+Zvalue+"="; //Build first part of URL
  73. URL += Val; //Convert Integer to String by concatenating it to the first part of URL
  74. if (PrintSerial==true) SerialUSB.print("Sending JSON Request"); //If required print header
  75. str_len = URL.length()+1; //Count number of characters on URL and store it
  76. URL.toCharArray(URLchar,str_len); //Convert URL string into URL char and store it
  77. zipatoclient.enableInsecure(); // Using HTTPS and peer cert. will not be able to auth.
  78. zipatoclient.postAsync(URLchar, ""); //Make Asynchronous POST Request
  79. tryagain:
  80. if (zipatoclient.finished()) { //If POST request finished then read response
  81. if (PrintSerial==true) { //Print to Serial if required
  82. SerialUSB.println();
  83. SerialUSB.print("Response Body:");
  84. while (zipatoclient.available() > 0) { //While there is response from server read response
  85. char c = zipatoclient.read(); //Load response to char
  86. SerialUSB.print(c);
  87. }
  88. SerialUSB.print(" Response Code: ");
  89. }
  90. respcode = zipatoclient.getResponseCode(); //Get response code 200 is succesful, 500 is server error
  91. if (PrintSerial==true) SerialUSB.println(respcode);
  92. zipatoclient.close(); //Close connection to save resources
  93. } else {
  94. if (PrintSerial==true) SerialUSB.print(".");
  95. retries += 1; //Add one to retries
  96. delay(100);
  97. if (retries>=10000) { //If retrying for 10 secs or more then break
  98. if (PrintSerial==true) SerialUSB.println();
  99. if (PrintSerial==true) SerialUSB.println("Timeout");
  100. if (respcode==0) respcode=500;
  101. goto timeout;
  102. }
  103. goto tryagain;
  104. }
  105. timeout:
  106. return respcode;
  107. }

photo
2

Update,


I also created a subroutine that makes requests synchronously to Zipato which also works, and saves some space by not using BridgeHTTPClient library;


  1. /***************************************************************************
  2. *FN_zipatosyncpost
  3. *This is a FUNCTION that assembles and sends HTTP synchronous POST to Zipato
  4. *servers to write values to Virtual Meters.
  5. *Each zipato Virtual Meter has 16 values.
  6. *RETURNS; Integer with Response Code
  7. *INPUTS;
  8. * String Zserial - Serial number for Zipato Controller
  9. * String Zapi - API Key from Virtual Meter
  10. * String Zep - EP Key from Virtual Meter
  11. * String Zvalue - Virtual Meter value placeholder name
  12. * int Val - Value to be writen into placeholder
  13. * boolean PrintSerial - If this value is TRUE this function will print more
  14. * information about Zipato response (debug).
  15. ***************************************************************************/
  16. int FN_zipatojsonpost(String Zserial, String Zapi, String Zep, String Zvalue,int Val, boolean PrintSerial){
  17. Process zipatoclient; //Declare Client
  18. //Declare Zipato Constants
  19. const String Zurl="https://my.zipato.com/zipato-web/remoting/attribute/"; //Define Zipato basic URL, this does not change
  20. //Declare Variables
  21. String URL; //String to hold complete URL
  22. int str_len; //Integer to hold lenght of URL
  23. char URLchar[200]; //Char array to hold URL
  24. int retries=0; //Integer to hold timeout timer
  25. unsigned int respcode; //Integer to hold response code from Zipato
  26. URL = Zurl+"set?serial="+Zserial+"&apiKey="+Zapi+"&ep="+Zep+"&"+Zvalue+"="; //Build first part of URL
  27. URL += Val; //Convert Integer to String by concatenating it to the first part of URL
  28. if (PrintSerial==true) Serial.println("Sending JSON Request"); //If required print header
  29. str_len = URL.length()+1; //Count number of characters on URL and store it
  30. URL.toCharArray(URLchar,str_len); //Convert URL string into URL char and store it
  31. zipatoclient.begin("curl");
  32. zipatoclient.addParameter("-D");
  33. zipatoclient.addParameter("-X"); //for other than GET
  34. zipatoclient.addParameter("POST"); //Type of request
  35. zipatoclient.addParameter("-k"); //enable insecure
  36. zipatoclient.addParameter("-w"); //format output
  37. zipatoclient.addParameter("%{response}\\n%{http_code}"); //{response}\n{responsecode}
  38. zipatoclient.addParameter(URLchar); //add Zipato URL
  39. zipatoclient.runAsynchronously();
  40. if (PrintSerial==true) Serial.print("Response:"); //print header if required
  41. while (zipatoclient.available() > 0) { //While there is response from server read response
  42. char c = zipatoclient.read(); //Load response to char
  43. if (c == '\n') respcode=zipatoclient.parseInt(); //If carriage return found get response code
  44. if ((PrintSerial==true) && (c != '\n')) Serial.print(c); //Print if required
  45. }
  46. if (PrintSerial==true) Serial.println(); //Print if required
  47. zipatoclient.close();
  48. return respcode;
  49. }


Unfortunately I have found a mayor roadblock, after being uploading data for a while to Zipato the YUN curl commands stopped working, after some research looks like there is a problem on the WIFI chip of the YUN which cannot be fixed by software and causes random issues like this one, I tried to apply all suggestions I could find without luck this is for sure on the YUN side, perhaps that is why the YUN is now an obsolete board replaced by TIAN. I will resume my tests with a UNO + Xbee wifi.

photo
1

I am also Trying to use Xbee S6B with UNO, if you have successfully done, can you send me all the source code to send HTTP request to my website.raman291992@gmail.com

photo
Leave a Comment
 
Attach a file