Hello Everybody,
I have an Arduino Uno with some kind of kit → Buy Open Garden Indoor (1 Node + 1 Gateway) Online
I am sending the data in the web server using shield and wifi module:
Shield: Communication Shield (XBee, Bluetooth, RFID) - XBee Shield - Arduino - Shop
Wifi Module: Cooking Hacks - Electronic and IoT Kits, tutorials and guides for Makers and Education
I want to make connection with Cayenne and try some stuff but it is unsuccessful. Bellow is the code that I use for the web server to connect:
/*
* OpenGarden sensor platform for Arduino from Cooking-hacks.
*
* Copyright (C) Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* a
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
* Version: 2.2
* Design: David Gascón
* Implementation: Victor Boria, Luis Martin & Jorge Casanova
*/
#include <OpenGarden.h>
#include <Wire.h>
//Enter here your data
const char server[] = "server";
const char server_port[] = "80";
const char wifi_ssid[] = "ssid";
const char wifi_password[] = "pass";
String wifiString;
char buffer[20];
int flag = 0; // auxiliar variable
DateTime myTime;
void setup() {
Serial.begin(9600);
OpenGarden.initSensors(); //Initialize sensors power
OpenGarden.sensorPowerON(); //Turns on the sensor power supply
delay(1000);
OpenGarden.initRF();
OpenGarden.initRTC();
wificonfig();
}
void loop() {
OpenGarden.receiveFromNode(); //Receive data from node
myTime = OpenGarden.getTime();
OpenGarden.printTime(myTime);
if (flag == 0){ //Only enter 1 time each hour
//Get Gateway Sensors
int soilMoisture0 = OpenGarden.readSoilMoisture();
float airTemperature0 = OpenGarden.readAirTemperature();
float airHumidity0 = OpenGarden.readAirHumidity();
float soilTemperature0 = OpenGarden.readSoilTemperature();
int luminosity0 = OpenGarden.readLuminosity();
//Get Node Sensors
Payload node1Packet = OpenGarden.getNodeData(node1);
int soilMoisture1 = node1Packet.moisture;
float airTemperature1 = node1Packet.temperature;
float airHumidity1 = node1Packet.humidity;
int luminosity1 = node1Packet.light;
int battery1 = node1Packet.supplyV;
//Create string of the floats to send it
dtostrf(airTemperature0,2,1,buffer);
String airTemperature0_wf = String (buffer);
dtostrf(airHumidity0,2,1,buffer);
String airHumidity0_wf = String (buffer);
dtostrf(soilTemperature0,2,1,buffer);
String soilTemperature0_wf = String (buffer);
dtostrf(airTemperature1,2,1,buffer);
String airTemperature1_wf = String (buffer);
dtostrf(airHumidity1,2,1,buffer);
String airHumidity1_wf = String (buffer);
/*
You must create strings with this structure: "node_id:sensor_type:value;node_id2:sensor_type2:value2;...."
Note the ";" between different structures
Where node_id:
0 - Gateway
1 - Node 1
2 - Node 2
3 - Node 3
And where sensor_type:
0 - Soil moisture
1 - Soil temperature
2 - Air Humidity
3 - Air Temperature
4 - Light level
5 - Battery level
6 - pH level
7 - Electrical conductivity
For example: "0:0:56;0:1:17.54;0:2:56.45"
This means that you send data of the gateway: Soil moisture=56, Soil temperature=17.54 and Air humidity=56.45
*/
//Cut data in several string because the wifi module have problems with longer strings
wifiString= "0:0:" + String(soilMoisture0) + ";0:1:" + soilTemperature0_wf + ";0:2:" + airHumidity0_wf;
sendwifi();
enterCMD();
wifiString = "1:0:" + String(soilMoisture1) + ";1:2:" + airHumidity1_wf + ";1:3:" + airTemperature1_wf + ";1:4:" + String(luminosity1);
sendwifi();
enterCMD();
wifiString= "0:3:" + airTemperature0_wf + ";0:4:" + String(luminosity0);
sendwifi();
enterCMD();
wifiString = "1:5:" + String(battery1);
sendwifi();
enterCMD();
Serial.print(battery1);
flag = 1;
delay(120000);
}
else if (flag == 1){
flag = 0;
}
}
//*********************************************************************
//*********************************************************************
void check() {
delay(3000);
autoflush();
}
void wificonfig() {
while (Serial.available() > 0) {
}
delay(3000);
enterCMD();
// Sets DHCP and TCP protocol
Serial.print(F("set ip dhcp 1\r"));
check();
Serial.print(F("set ip protocol 18\r"));
check();
// Configures the way to join the network AP, sets the encryption of the
// network and joins it
Serial.print(F("set wlan join 0\r")); //The auto-join feature is disabled
check();
Serial.print(F("set wlan phrase "));
Serial.print(wifi_password);
Serial.print(F("\r"));
check();
Serial.print(F("join "));
Serial.print(wifi_ssid);
Serial.print(F("\r"));
check();
}
void enterCMD() {
Serial.println("");
// Enters in command mode
Serial.print(F("$$$"));
delay(100);
check();
Serial.flush();
}
void sendwifi() {
Serial.print(F("set i h 0\r"));
check();
Serial.print(F("set d n "));
Serial.print(server);
Serial.print(F("\r"));
check(); //Insert here your IP
//Configures HTTP connection
Serial.print(F("set i r "));
Serial.print(server_port);
Serial.print(F("\r"));
check();
Serial.print(F("set o f 1\r"));
check();
Serial.print(F("set c r GET$/set_sensors.php?data="));
Serial.print(wifiString);
Serial.print(F("\r"));
check();
// Calls open to launch the configured connection.
Serial.print(F("open\r"));
check();
Serial.print(F("open\r"));
}
void autoflush()
{
while (Serial.available() > 0)
{
Serial.read();
}
}
Can somebody help me a little bit with connection to Cayenne and furthermore use the opengarden shield for taking data from sensors.
Best Wishes,
Thanks