senor data showing on the serial monitor but not uploading to thingspeak channel | 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
senor data showing on the serial monitor but not uploading to thingspeak channel
No permission to create posts
March 14, 2018
8:17 am
Avatar
Niraj
New Member
Members
Forum Posts: 2
Member Since:
February 5, 2018
sp_UserOfflineSmall Offline

I tried to connect the atlas ph sensor to the arduino since it has been connnected succcessfully and showing on value on serial monitor but while sending the value through gsm sim900 its not able to send 

 

#include <SoftwareSerial.h> //we have to include the SoftwareSerial library, or else we can't use it
#define rx 2 //define what pin rx is going to be
#define tx 3 //define what pin tx is going to be
#include <String.h>

SoftwareSerial myserial(rx, tx); //define how the soft serial port is going to work
SoftwareSerial mySerial(7, 8);
String inputstring = ""; //a string to hold incoming data from the PC
String sensorstring = ""; //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false; //have we received all the data from the PC
boolean sensor_string_complete = false; //have we received all the data from the Atlas Scientific product
boolean pin2=LOW,pin3=LOW,pin4=LOW,pin5=LOW,pin6=LOW;
float pH; //used to hold a floating point number that is the pH

void setup(void)
{ //set up the hardware
pinMode(0,INPUT);
pinMode(1,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
pinMode(6,INPUT);
Serial.begin(9600); //set baud rate for the hardware serial port_0 to 9600
myserial.begin(9600); //set baud rate for the software serial port to 9600
inputstring.reserve(10); //set aside some bytes for receiving data from the PC
sensorstring.reserve(30); //set aside some bytes for receiving data from Atlas Scientific product
}
void serialEvent()
{ //if the hardware serial port_0 receives a char
inputstring = Serial.readStringUntil(13); //read the string until we see a <CR>
input_string_complete = true; //set the flag used to tell if we have received a completed string from the PC
}
void loop(void)
{ //here we go...
if (input_string_complete) //if a string from the PC has been received in its entirety
{
myserial.print(inputstring); //send that string to the Atlas Scientific product
myserial.print('
'); //add a <CR> to the end of the string
inputstring = ""; //clear the string
input_string_complete = false; //reset the flag used to tell if we have received a completed string from the PC
}
if (myserial.available() > 0) //if we see that the Atlas Scientific product has sent a character
{
char inchar = (char)myserial.read(); //get the char we just received
sensorstring += inchar; //add the char to the var called sensorstring
if (inchar == '
') //if the incoming character is a <CR>
{
sensor_string_complete = true; //set the flag
}
}
if (sensor_string_complete == true) //if a string from the Atlas Scientific product has been received in its entirety
{
Serial.println(sensorstring); //send that string to the PC's serial monitor
delay(1000);
sensorstring = ""; //clear the string
sensor_string_complete = false; //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
delay(100);
Send2niraj();
if (mySerial.available())
Serial.write(mySerial.read()) ;
}
}

void Send2niraj()
{
mySerial.println("AT");
delay(1000);
mySerial.println("AT+CPIN?");
delay(1000);
mySerial.println("AT+CREG?");
delay(1000);
mySerial.println("AT+CGATT?");
delay(1000);
mySerial.println("AT+CIPSHUT");
delay(1000);
mySerial.println("AT+CIPSTATUS");
delay(2000);
mySerial.println("AT+CIPMUX=0");
delay(2000);
ShowSerialData();
mySerial.println("AT+CSTT=\"internet\"");//start task and setting the APN,
delay(3000);
ShowSerialData();
mySerial.println("AT+CIICR");//bring up wireless connection
delay(3000);
ShowSerialData();
mySerial.println("AT+CIFSR");//get local IP adress
delay(2000);
ShowSerialData();
mySerial.println("AT+CIPSPRT=0");
delay(3000);
ShowSerialData();
mySerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection
delay(6000);
ShowSerialData();
mySerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();
String str="GET https://api.thingspeak.com/update?api_key=CY8K1V00EZ5W26ZX&field1=0" + String(sensorstring);
mySerial.println(str);//begin send data to remote server
delay(4000);
ShowSerialData();
mySerial.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
mySerial.println();
ShowSerialData();
mySerial.println("AT+CIPSHUT");//close the connection
delay(100);
ShowSerialData();
}

void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());}

March 14, 2018
2:17 pm
Avatar
Niraj
New Member
Members
Forum Posts: 2
Member Since:
February 5, 2018
sp_UserOfflineSmall Offline

i got the answer i was wrong with string(sensorstring)...

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
22 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:

briskpanda, Dejw0089, Yassine Ben Salah, anis, 43994554AKS, suda

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457