hey guys,
Im trying to send POST request with sim900 connected to arduino uno.
I send it to firebase functions but I dont get it in the function.
I will be happy to get solution for my problem,
or alternative way that i can store data from sensors to firebase with sim900 or any other celular network solution).
arduino code:
#include<SoftwareSerial.h>
SoftwareSerial client(7,8);
String reading="{ "testID" : 1, }";
void setup()
{
Serial.begin(9600);
client.begin(9600);
delay(500);if(client.available())
{
Serial.println("Connected");
}
else
{
Serial.println("NotConnected");
}
//initSIM();
connectGPRS();
connectHTTP();
}void loop()
{
}void connectGPRS()
{
client.println("AT+SAPBR=3,1,"Contype","GPRS"");
delay(1000);
ShowSerialData();client.println("AT+SAPBR=3,1,"APN","www"");//APN
delay(1000);
ShowSerialData();client.println("AT+SAPBR=1,1");
delay(1000);
ShowSerialData();client.println("AT+SAPBR=2,1");
delay(1000);
ShowSerialData();
}void connectHTTP()
{
client.println("AT+HTTPINIT");
delay(1000);
ShowSerialData();client.println("AT+HTTPPARA="CID",1");
delay(1000);
ShowSerialData();client.println("AT+HTTPPARA="URL","www.us-central1-**************.cloudfunctions.net/helloWorld"");//Public server IP address
delay(1000);
ShowSerialData();client.println("AT+HTTPPARA="CONTENT","application/json"");
delay(1000);
ShowSerialData();client.println("AT+HTTPDATA=" + String(reading.length()) + ",100000");
delay(1000);
ShowSerialData();client.println(reading);
delay(1000);
ShowSerialData;client.println("AT+HTTPACTION=1");
delay(1000);
ShowSerialData();client.println("AT+HTTPREAD");
delay(1000);
ShowSerialData();client.println("AT+HTTPTERM");
delay(1000);
ShowSerialData;
}void ShowSerialData()
{
while(client.available()!=0)
{
Serial.write(client.read());
delay(100);
}
}
firebase function:
const functions = require('firebase-functions');
// Create and Deploy Your First Cloud Functions
// শুরু করুন: লিখুন, পরীক্ষা করুন এবং আপনার প্রথম ফাংশন স্থাপন করুন | Cloud Functions for Firebaseexports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
// Check for POST request
if (request.method !== "POST") {
console.log('Please send a POST request');
}
if (request.method !== "GET") {
console.log('Please send a GET request');
}
let data = request.body;
console.log(Hello from Firebase! ${JSON.stringify(data)}
);
// console.log('testing: ' + data[0]);
// console.log('testing: ' + data.longitude);
// console.log('testing: ' + data['longitude']);
});
Thank you all!