Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Bridge.h>
- #include <Process.h>
- #include <Wire.h>
- #include <WiFi.h>
- #include <SPI.h>
- #include <Console.h>
- char ssid[] = "xxxxxxxxxxxxxxx"; // the name of your network
- int status = WL_IDLE_STATUS;
- IPAddress ip;
- String setupHtmlString;
- String createHtmlString;
- String curlCreate(String a);
- String curlSetup(String b);
- void setup() {
- // put your setup code here, to run once:
- Bridge.begin();
- Console.begin();
- // Console.begin(9600);
- while (!Console) {
- }
- /*
- * Defintion Block
- */
- char *attribute[][5] = {
- {"0x0201", "0x0000", "0x019", "0x0", "15"},
- {"0x0201", "0x0000", "0x018", "0x0", "15"},
- {"0x0201", "0x0000", "0x017", "0x0", "15"},
- {"0x0000", "0x0000", "0x001", "0x0", "15"}
- };
- int numberOfAttributes = (sizeof attribute / 10);
- /*
- * Create Block
- */
- String createHtmlString = String("http://");
- String route = String("/OpenEMan/register/create.json?");
- String apikey = String("apikey=");
- String nodeMAC = String("&nodeMAC=");
- String fromAddress = String("&fromAddress=");
- String timeout = String("&timeout=");
- //Data entry from User
- String apikeyEntered = String("11133d815882bc03a4a97789d983d189");
- String serverAddress = String("xxx.xxx.xxx.xxx");
- String timeoutEntered = String("15");
- String MACAddressFAKE = String("01:02:03:04:05:10");
- String IPaddressFAKE = String("xxx.xxx.xxx.xxx");
- createHtmlString.concat(serverAddress);
- createHtmlString.concat(route);
- createHtmlString.concat(apikey);
- createHtmlString.concat(apikeyEntered);
- createHtmlString.concat(nodeMAC);
- createHtmlString.concat(MACAddressFAKE);
- createHtmlString.concat(fromAddress);
- createHtmlString.concat(IPaddressFAKE);
- createHtmlString.concat(timeout);
- createHtmlString.concat(timeoutEntered);
- Console.print("Create String:");
- Console.println(createHtmlString);
- //String nodeid = String("100");
- String nodeid;
- nodeid=curlCreate(createHtmlString);
- Console.print("Nodeid: ");
- Console.println(nodeid);
- /*
- * Setup Block
- */
- for ( int go = 0; go < numberOfAttributes; go++) {
- Console.println(go);
- String groupIDA = attribute[go][0];
- groupIDA += ",";
- String attributeIDA = attribute[go][1];
- attributeIDA += ",";
- String attributeNumberA = attribute[go][2];
- attributeNumberA += ",";
- String attributeDefaultValueA = attribute[go][3];
- String timeoutA = attribute[go][4];
- String setupHtmlString = String("http://xxx.xxx.xxx.xxx");
- String route = String("/OpenEMan/register/setup.json?");
- // setupHtmlString.concat(IPAddress);
- setupHtmlString.concat(route);
- String apikeyS = String("apikey=");
- apikeyS.concat(apikeyEntered);
- Console.println(apikeyS);
- String nodeidS = String("&node=");
- nodeidS.concat(nodeid);
- Console.println(nodeidS);
- String json = String("&json=");
- json.concat(groupIDA);
- json.concat(attributeIDA);
- json.concat(attributeNumberA);
- json.concat(attributeDefaultValueA);
- Console.println(json);
- String timeoutS = String("&timeout=");
- timeoutS.concat(timeoutA);
- // timeoutS.concat(timeoutSV);
- setupHtmlString.concat(apikeyS);
- Console.println(setupHtmlString);
- Console.println("Breaks");
- setupHtmlString.concat(nodeidS);
- Console.println("Here");
- Console.println(setupHtmlString);
- setupHtmlString.concat(json);
- Console.println(setupHtmlString);
- setupHtmlString.concat(timeoutS);
- Console.println(setupHtmlString);
- String responseString;
- responseString=curlSetup(setupHtmlString);
- Console.println(responseString);
- }
- }
- String curlCreate(String a){
- Process p; // Create a process and call it "p"
- p.begin("curl"); // Process that launch the "curl" command
- p.addParameter(a); // Add the URL parameter to "curl"
- p.run(); // Run the process and wait for its termination
- int i = 0;
- char createResponse[100];
- while (p.available() > 0) {
- char c = p.read();
- createResponse[i] = c;
- i++;
- }
- Console.flush();
- char isReg;
- isReg = createResponse[i];
- int sizeOfResponse = i - 3;
- String nodeid;
- Console.println(createResponse);
- for (int aa = 0; aa < sizeOfResponse; aa++) {
- nodeid += createResponse[aa + 1];
- }
- Console.print("1Nodeid: ");
- Console.println(nodeid);
- return nodeid;
- }
- String curlSetup(String b){
- Console.println("CurlSetup");
- Console.println(b);
- Process o; // Create a process and call it "p"
- o.begin("curl"); // Process that launch the "curl" command
- o.addParameter(b); // Add the URL parameter to "curl"
- o.run(); // Run the process and wait for its termination
- Console.flush();
- int j = 0;
- char setupResponse[100];
- Console.println("CurlSetup");
- while (o.available() > 0) {
- char d = o.read();
- setupResponse[j] = d;
- j++;
- Console.println(setupResponse);
- }
- Console.flush();
- Console.println("CurlSetup");
- return setupResponse;
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
Advertisement
Add Comment
Please, Sign In to add comment