Sending Data to Things Speak Server With HTTP Post Using SIM7600 and Arduino.
by electronicsworkshop111 in Circuits > Arduino
5 Views, 0 Favorites, 0 Comments
Sending Data to Things Speak Server With HTTP Post Using SIM7600 and Arduino.
In this project, we will learn how we can send data to things speak server with http post using SIM7600 and Arduino.
In our previous projects, We used SIM800 / SIM900 series of 2G GSM module to send HTTP requests but 2G services is band in most of the European Countries. So, there might be problem in remote monitoring or sending data to server using wireless communications. We can solve this problem by using 4G LTE module SIM7600 and Arduino.
This 4G GSM LTE Module allows you to add voice, text, location-tracking, voice, SMS, and data to your application.One of the big advantage of Sim7600 4G LTE module is its covers a wide range of area and signal/connectivity is available almost everywhere.
In this project,We use Cellular IOT with 4G LTE SIM7600 Modem and Send Data to Server with HTTP Post using SIM7600 LTE module
PCB MANUFACTURER
This project is sponsored by PCBWAY. It is world fastest pcb manufacturing company.
You Will get FREE prototype pcb from PCBWAY. So do not be late to register and place your first order from PCBWAY
If you want to order pcb from PCBWAY . CLICK IN THE LINK BELOW:
https://www.pcbway.com/QuickOrderOnline.aspx?from=electronicsworkshops
HTTP Post With SIM7600 and Arduino
We are going to send DHT11 temperature and humidity data to things speak server using SIM7600 and Arduino. We will use HTTP Post method and with SIM7600 AT Commands. In our previous article also we have already tested AT commands for checking HTTP data.
Hardware Connections of SIM7600 and Arduino With DHT11 Sensor
DHT11 temperature and humidity sensor has 3 pins VCC ,GND and Data .
vcc is connected to 3.3 volt.
GND to Ground
Data to D3 pin of the module
PROGRAMMING
#include <stdio.h> #include <string.h> #include <DHT.h> //Change the API key to yours String Apikey = "***************"; #define DEBUG true #define LTE_RESET_PIN 6 #define LTE_PWRKEY_PIN 5 #define LTE_FLIGHT_PIN 7 #define Sensor_PIN 3 //D3-DHT11 DHT dht(Sensor_PIN,DHT11); void setup() { SerialUSB.begin(115200); //while (!SerialUSB) { ; // wait for Arduino serial Monitor port to connect } Serial1.begin(115200); //Serial1.begin(UART_BAUD, SERIAL_8N1, MODEM_RXD, MODEM_TXD); pinMode(LTE_RESET_PIN, OUTPUT); digitalWrite(LTE_RESET_PIN, LOW); pinMode(LTE_PWRKEY_PIN, OUTPUT); digitalWrite(LTE_RESET_PIN, LOW); delay(100); digitalWrite(LTE_PWRKEY_PIN, HIGH); delay(2000); digitalWrite(LTE_PWRKEY_PIN, LOW); pinMode(LTE_FLIGHT_PIN, OUTPUT); digitalWrite(LTE_FLIGHT_PIN, LOW);//Normal Mode delay(5000); /*ModuleState = moduleStateCheck(); if (ModuleState == false) //if it's off, turn on it. { digitalWrite(PWR_KEY, LOW); delay(3000); digitalWrite(PWR_KEY, HIGH); delay(10000); SerialUSB.println("Now turnning the SIM7600 on."); }*/ sendData("AT+CCID", 3000, DEBUG); sendData("AT+CREG?", 3000, DEBUG); sendData("AT+CGATT=1", 1000, DEBUG); sendData("AT+CGACT=1,1", 1000, DEBUG); sendData("AT+CGDCONT=1,\"IP\",\"apn\"", 1000, DEBUG); //sendData("AT+CIPSTART=\"TCP\",\"www.mirocast.com\",80", 2000, DEBUG); SerialUSB.println("4G HTTP Test Begin!"); dht.begin(); delay(1000); } void loop() { //--------Get temperature and humidity------------- float h = dht.readHumidity(); float t = dht.readTemperature(); SerialUSB.print("Humidity: "); SerialUSB.print(h); SerialUSB.println("%"); SerialUSB.print("Temperature: "); SerialUSB.print(t); SerialUSB.println("*C"); delay(1000); //-----------HTTP--------------------- String http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey + "&field1=" + (String)t + "&field2=" + (String)h + "\"\r\n"; SerialUSB.println(http_str); sendData("AT+HTTPINIT\r\n", 2000, DEBUG); sendData(http_str, 2000, DEBUG); sendData("AT+HTTPACTION=0\r\n", 3000, DEBUG); sendData("AT+HTTPTERM\r\n", 3000, DEBUG); delay(5000); } bool moduleStateCheck() { int i = 0; bool moduleState = false; for (i = 0; i < 5; i++) { String msg = String(""); msg = sendData("AT", 1000, DEBUG); if (msg.indexOf("OK") >= 0) { SerialUSB.println("SIM7600 Module had turned on."); moduleState = true; return moduleState; } delay(1000); } return moduleState; } String sendData(String command, const int timeout, boolean debug) { String response = ""; Serial1.println(command); long int time = millis(); while ( (time + timeout) > millis()) { while (Serial1.available()) { char c = Serial1.read(); response += c; } } if (debug) { SerialUSB.print(response); } return response; }