PLEASE HELP V2 | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
PLEASE HELP V2
No permission to create posts
October 31, 2018
2:22 am
Avatar
KingVic
New Member
Members
Forum Posts: 4
Member Since:
October 11, 2018
sp_UserOfflineSmall Offline

Hi guys!

Forgive me for i am completely noob to arduino

Basically I want to get a real time feed for temperature humidity, sound, UV, and PIR to show on my ThingSpeak channel (under seperate fields e.g. Field 1 for temperature, Field 2 for humidity etc...), where the data is sent from a Node to a Gateway, and then the Gateway uploads it to ThingSpeak. (The Client is the Arduino with all the sensors which needs to transmit data to another Arduino (THE GATEWAY).)

Currently, It seems that the transmitted data is received and im getting accurate numbers for temperature, humidity, and sound however( IN MY CLIENT) my GATEWAY'S serial monitor - only says it CONNECTED to the node but does not upload or show any sensor values. It does not show anything else but that it is connected. The data is also not uploaded to THINGSPEAK... PLEASE HELP...

Here is my new GATEWAY CODE:

#include
#include
#include
#include
RH_RF95 rf95;

//If you use Dragino IoT Mesh Firmware, uncomment below lines.
//For product: LG01.
#define BAUDRATE 115200

String myWriteAPIString = "JM6LFE8TP2673IMO";
float frequency = 868.0;
String dataString = "";

void setup()
{
Bridge.begin(BAUDRATE);
Console.begin();
// while(!Console);
if (!rf95.init())
Console.println("init failed");
;
// Setup ISM frequency
rf95.setFrequency(frequency);
// Setup Power,dBm
rf95.setTxPower(13);

Console.println("LoRa Gateway Example --");
Console.println(" Upload Single Data to ThinkSpeak");
}

void loop()
{

if (rf95.waitAvailableTimeout(2000))// Listen Data from LoRa Node
{
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];//receive data buffer
uint8_t len = sizeof(buf);//data buffer length

if (rf95.recv(buf, &len))//Check if there is incoming data
{ /*
recdata( buf, len);
Console.print("Get LoRa Packet: ");
for (int i = 0; i < len; i++)
{
Console.print(buf[i],HEX);
Console.print(" ");
}*/
Console.println();
if(buf[0] == 1||buf[1] == 2||buf[2] == 5) //Check if the ID match the LoRa Node ID
{
uint8_t data[] = " Server ACK";//Reply
data[0] = buf[0];
data[1] = buf[1];
data[2] = buf[2];
rf95.send(data, sizeof(data));// Send Reply to LoRa Node
rf95.waitPacketSent();
int newData[7] = {0, 0, 0, 0, 0, 0, 0}; //Store Sensor Data here<<<<<<<<<<<<<Might need to change here
for (int i = 0; i < 7; i++)
{
newData[i] = buf[i + 3];
}
int Tem = newData[0];
int hum = newData[1];
int sou = newData[2];
int s_d = newData[3];
int u_v = newData[4];
int uvd = newData[5];
int pir = newData[6];

//Show Temperature
Console.print("Get Temperature: ");
Console.print(Tem,DEC);
Console.println(" C");
//Show Humidity
Console.print("Get Humidity: ");
Console.print(hum,DEC);
Console.println(" %");
//Show Sound
Console.print("Get Sound: ");
Console.print(sou);
Console.print(".");
Console.print(s_d);
Console.println(" dB");
//Show UV
Console.print("Get UV: ");
Console.print(u_v);
Console.print(".");
Console.print(uvd);
Console.println(" mV");
//Show PIR
Console.print("Stupid Human: ");
Console.print(pir);
Console.println(" Idoits");

dataString ="field1=";
dataString += String(Tem);
dataString +="&field2=";
dataString += String(hum);
dataString +="&field3=";
dataString += String(sou);
dataString +=".";
dataString += String(s_d);
dataString +="&field4=";
dataString += String(u_v);
dataString +=".";
dataString += String(uvd);
dataString +="&field5=";
dataString += String(pir);

uploadData();
dataString="";
}
}
else
{
Console.println("recv failed");
}
}
}

void uploadData() //Upload Data to ThingSpeak
{

// form the string for the URL parameter, be careful about the required "
String upload_url = "https://api.thingspeak.com/update?api_key=&quot;;
upload_url += myWriteAPIString;
upload_url += "&";
upload_url += dataString;

Process p; // Create a process and call it "p", this process will execute a Linux curl command
p.begin("curl");
p.addParameter("-k");
p.addParameter(upload_url);
p.run(); // Run the process and wait for its termination

Console.println(upload_url);
Console.println("Call Finished");
Console.println("####################################");
Console.println("");
}
HERE IS MY CLIENT CODE

//#include
#include
//#include
#define DHTTYPE DHT11

#include
//#include
#include

#include
#include
#include
#include
//#include
#define MINUTE_VALUE 1

RH_RF95 rf95;

//#### PIR ####
int PIR1 = A3;
int PIR2 = A4;
int PIR3 = A5;
int state = LOW; // by default, no motion detected
int sam, isam;
int state1 = LOW, state2 = LOW;

int i = 0; // variable to store the sensor status (value)
int counter = 0, backup = 0;
int second = 0, minute = 0;
int flag_status = 0;

//#### DHT ####
#define DHT_Pin A0
DHT dht(DHT_Pin, DHTTYPE);
byte Err = 0;
char node_ID[3] = {1,2,5};
float frequency = 868.0;
unsigned int count = 1;
float read_Tem;
float read_Hum;
char dht_data[4];

//#### SDM ####
const int soundPin = A1;
//int DPin = 2;
float dbValue;
char db_data[2];

//#### For Internal Temperature Sensor and Servo ####
/*const int sensePin = A2;
int sensorInput = 0; //The variable we will use to store the sensor input
double Temp; //The variable we will use to store temperature in degrees.
*/
int servoPin1 = 3;
int servoPin2 = 5;
//Servo servo1, servo2;

//#### UV ####
const int UVPin = A2;
float sensorValue_UV;
float UV_index;
char uv_data[2];

void setup()
{
Serial.begin(9600);
pinMode(PIR1, INPUT);
pinMode(PIR2, INPUT);
pinMode(PIR3, INPUT);
// servo1.attach(servoPin1);
// servo2.attach(servoPin2);
dht.begin();
Timer1.initialize(1000000);
Timer1.attachInterrupt(PIR_data_Upload);

}
void loop()
{
Inital();
Read_DHT();
Upload_to_Gateway();
MeasuredSound();
readVcc();
servo();
sensor_UV();
PIR_data_Upload();
sensor1();
sensor2();
sensor3();
}
void Inital()
{

if(!rf95.init())
{
Serial.println("Initial Failed");
}
rf95.setFrequency(frequency); //Setup ISM Frequency
rf95.setTxPower(13); //Setup for Power (dBm)

Serial.println("##### Sai and Vichai Project #####");
Serial.print("LoRa End Node ID: ");
for(int i = 0; i<3; i++)
{
Serial.print(node_ID[i], HEX);
}
Serial.println();
}

void Upload_to_Gateway()
{
Read_DHT();
MeasuredSound();
Serial.print("########### ");
Serial.print("COUNT= ");
Serial.print(count);
Serial.println(" ###########");
count++;

char send_Data[100] = {0};
char PIR_data[10] = {0};
int datalength = sizeof(send_Data);
if (flag_status)
{
backup = counter;
PIR_data[0] = backup;
flag_status = 0;
}

send_Data[0] = node_ID[0]; //Node ID
send_Data[1] = node_ID[1]; //Node ID
send_Data[2] = node_ID[2]; //Node ID

send_Data[3] = dht_data[0]; //Temperature
send_Data[4] = dht_data[1]; //Humidity

send_Data[5] = db_data[0]; //Sound Integar
send_Data[6] = db_data[1]; //Sound Decimal

send_Data[7] = uv_data[0]; //UV Integar
send_Data[8] = uv_data[1]; //UV Decimal

send_Data[9] = PIR_data[0]; //PIR counting value

Serial.print("Temperature = ");
Serial.print(send_Data[3], DEC);
Serial.println(" % ");
Serial.print("Humidity = ");
Serial.print(send_Data[4], DEC);
Serial.println(" C ");
Serial.print("Sound = ");
Serial.print(send_Data[5], DEC);
Serial.print(".");
Serial.print(send_Data[6], DEC);
Serial.println(" dB ");
Serial.print("UV = ");
Serial.print(send_Data[7], DEC);
Serial.print(".");
Serial.print(send_Data[8], DEC);
Serial.println(" mV ");
Serial.print("Stupid Human = ");
Serial.print(send_Data[9], DEC);
Serial.println(" Idoits ");
delay(1000);

unsigned char send_Buf[200] = {0};
for(int i = 0; i0)return(decPart); //return the decimal part of float number if it is available
else if(decPart<0)return((-1)*decPart); //if negative, multiply by -1
else if(decPart=0)return(00); //return 0 if decimal part of float number is not available
}

void sensor_UV()
{
sensorValue_UV = analogRead(UVPin);
UV_index = sensorValue_UV/1024*5;

uv_data[0] = int(UV_index);
uv_data[1] = getDecimal(UV_index);
/*
Serial.print("UV_index = ");
Serial.println(UV_index);
Serial.print("uv int = ");
Serial.println(uv_data[0],DEC);
Serial.print("uv dec= ");
Serial.println(uv_data[1],DEC); // Get Decimal part
Serial.println("#############");
delay(1000);
*/
}

long readVcc()
{
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif

delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA,ADSC)); // measuring

uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both

long result = (high<= 22)
{
// servo1.write(170);
// servo1.write(170);
}
else if(read_Tem <= 20)
{
// servo2.write(5);
// servo2.write(5);
}
}

void PIR_data_Upload()
{
second++;
if (second == 59)
{
second = 0;
minute++;
}
if (minute == MINUTE_VALUE)
{
second = 0;
minute = 0;
flag_status = 1;
}
}
void sensor1()
{
i = digitalRead(PIR1); // read sensor value
if (i == HIGH)
{ // check if the sensor is HIGH

delay(100); // delay 100 milliseconds

if (state == LOW)
{
Serial.println("SENSOR 111 is detected!");
state = HIGH; // update variable state to HIGH
counter++;

}
}
else
{
delay(200); // delay 200 milliseconds

if (state == HIGH)
{
Serial.println("SENSOR 111 is stopped!");
state = LOW; // update variable state to LOW
}
}
}

void sensor2()
{
sam = digitalRead(PIR2); // read sensor value
if (sam == HIGH)
{ // check if the sensor is HIGH
delay(100); // delay 100 milliseconds

if (state1 == LOW)
{
Serial.println("SENSOR 222 is detected!");
state1 = HIGH; // update variable state to HIGH
counter++;
}
}
else
{
delay(200); // delay 200 milliseconds

if (state1 == HIGH)
{
Serial.println("SENSOR 222 is stopped!");
state1 = LOW; // update variable state to LOW
}
}
}

void sensor3()
{
isam = digitalRead(PIR3); // read sensor value
if (isam == HIGH)
{ // check if the sensor is HIGH
delay(100);

if (state2 == LOW)
{
Serial.println("SENSOR 333 is detected!");
state2 = HIGH; // update variable state to HIGH
counter++;
}
}
else
{
delay(200); // delay 200 milliseconds

if (state2 == HIGH)
{
Serial.println("SENSOR 333 is stopped!");
state2 = LOW; // update variable state to LOW
}
}

}

October 31, 2018
11:35 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Sounds like an intense project. Welcome to ThingSpeak (and Arduino).

I think we should focus on the gateway. Lets get that to post data by itself before we get the client involved.
I might be able to guess from the code, but can you describe how the gateway is connected to the internet? Is it Ethernet card, Wifi card, or some other device (LORA gateway)?

Even before that, you should test the connection to thingSpeak from your network. Can you connect to the same network that your gateway is using with a computer and paste the update REST call into a browser to make sure it updates your channel?
https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&field1=123

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
12 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

khanhNguyen_CT, susyburr, quijano__, meosuckhoe, briskpanda, Dejw0089

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457