void send_mqtt(String topic, String message) {
// print to serial monitor
Serial.print("Publish message: ");
Serial.println(message);
// publish message
int packetIdPub1 = client.publish(topic, message);
Serial.print("Publish acknowledged: ");
Serial.println(packetIdPub1);
}
#include <PubSubClient.h>
#include <TinyGsmClient.h>
#include <TinyGsmClientSIM7080G.h>
#include "secrets.h"
#define LED_BUILTIN 2
// Your GPRS credentials
// Leave empty, if missing user or pass
const char apn[] = APN;
const char user[] = USER;
const char pass[] = PASS;
// Poner los datos para conectarse al mqtt
const char* mqtt_server = SERVER;
const char* mqtt_user = USER_MQTT;
const char* mqtt_pass = PASS_MQTT;
#define TINY_GSM_DEBUG Serial
TinyGsm modem(Serial1);
TinyGsmClient client(modem);
PubSubClient mqtt(client);
// Está funcion se ejecuta si se hace un ping al servidor
void callback(char* topic, byte* payload, unsigned int length) {
#include <SIM7080G.h>
#include "PubSubClient.h"
#include "TinyGsmClient.h"
#define DEBUG true
/*
* Define your module's pins
* (hardware serial port must be used)
*/
#define MODEM_RST 5
#define MODEM_PWKEY 4
#define MODEM_POWER_ON -1
#define MODEM_TX 23
#define MODEM_RX 19
#define MODEM_BAUD 9600
/*
* Define your APN data
*/
#define APN "apn"
#define USERNAME ""
#define PASSWORD ""
/*
* Define the hostname and port
*/
#define HOSTNAME "test.mosquitto.org"
#define HOSTPORT 1883
/*
* Define MQTT topics
*/
#define MQTT_TOPIC "sim7080g/telemetry"
#define MQTT_TOPIC_SUBSCRIBE "sim7080g/control"
char *strToChar(char string[]){
// string = "hola";
char *cstr = malloc(strlen(string));
strcpy (cstr, string);
return cstr;
}
#include <PubSubClient.h>
#include <Arduino.h>
#include <TinyGsmClient.h>
#define MODEM_RST -1
#define MODEM_PWKEY 5
#define MODEM_POWER_ON 4
#define MODEM_TX 23
#define MODEM_RX 22
#define MODEM_BAUD 9600
#define APN "internet.itelcel.com"
#define USERNAME ""
#define PASSWORD ""
#define TOPIC "Topic"
#define PAYLOAD "Hola"
//conectividad
TinyGsm modem(Serial2);
TinyGsmClient client(modem);
PubSubClient mqtt(client);
char mqttServer[] = "mqtt.thingspeak.com";
char mqttPort[] = "1883";
void setup() {
// put your setup code here, to run once:
pinMode(MODEM_PW
#include <TinyGsmClient.h>
#include <PubSubClient.h>
TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
PubSubClient MQTT(client);
void Mqtt_send(String topic , String message)
{
MQTT.publish(topic.c_str(), message.c_str());
}
void sendmqtt(str topic ,str msg)
{
Serial.println(String("AT+NSOST=0,\"mqtt.thingspeak.com\",1883,")+String(topic.length())+String(",")+String(msg.length())+String(",")+topic+msg);
Serial.println("AT+NSOST=0,\"mqtt.thingspeak.com\",1883,4,4,\"1\"");
Serial.println();
}
#include <Arduino.h>
#include <TinyGsmClient.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#define pwmmoter 5
#define C_SPEED MOTOR_100_PERCENT
#define DEVICE_NAME "test"
#define AT_COMMAND_DELAY 1000
#define PUB_TOPIC "test"
#define PUB_TOPIC "test"
#define MQTT_SERVER "mqtt.thingspeak.com"
#define MQTT_PORT 1883
TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
PubSubClient mqtt(client);
void motor_stop() {
analogWrite(pwmmoter, 0);
}
void motor_move(int speed) {
analogWrite(pwmmoter, speed);
}
void motor_foward() {
motor_move(C_SPEED);
}
void
void mqtt_send(const char* topic, const char* message) {
if (!mqtt.connected()) {
reconnect();
}
mqtt.publish(topic, message);
Serial.print("Mensaje publicado: ");
Serial.println(topic);
Serial.println(message);
}
void sendMqtt(String topic, String message) {
if (client.connected()) {
Serial.println("Publishing: " + message + " to " + topic);
client.publish(topic.c_str(), message.c_str());
}
}
int send_message(String message){
Serial.print("AT+CMGS=\"+57");
Serial.print(PHONE_NUMBER);
Serial.println("\"");
delay(100);
Serial.println(message);
delay(100);
Serial.println((char)26);
delay(100);
return 1;
}
#include "PubSubClient.h"
#include "TinyGsmClient.h"
#include <WiFi.h>
#include <WiFiClient.h>
#define SERVER "mqtt.thingspeak.com"
#define SERVERPORT 1883
#define user "subscribe"
#define pass "subscribe"
#define TOPIC "channels/1037994/publish/E6ZMPK6QXCKGJU6E"
# define USERAGENT "Arduino"
#define PIN_TXD 15
#define PIN_RXD 16
#define PIN_RST 26
#define PIN_RTS 25
#define PIN_CTS 27
#define PIN_DCD 33
#define PIN_DSR 32
#define PIN_DTR 14
#define PIN_RI 12
#define PIN_PWR 13
unsigned long lastMillis = 0;
unsigned long currentMillis = 0;
WiFiClient net;
TinyGsm modem(Serial1);
void sendMqtt(char *topic, char *message)
{
mqttClient.publish(topic, message);
}
void sendmqtt(String topic, String mensaje)
{
if (mqtt.connected()){
mqtt.publish(topic,mensaje);
Serial.println(topic);
Serial.println(mensaje);
}
}
#include <Arduino.h>
#include <SIM7080G.h>
#include <WiFi.h> //Include the Wi-Fi library
#include <PubSubClient.h>
#include <string.h>
char ssid[] = "my_wifi_name";
char pass[] = "my_wifi_pass";
char server[] = "mqtt.thingspeak.com";
char topic[] = "channels/948297/publish/";
char clientID[] = "clientID";
char key[] = "A1DG0I9XWENHRXJL";
char mensaje[] = "field1=10&field2=20";
WiFiClient espClient;
PubSubClient client(espClient);
#define PIN_SIM_PWR_ON 34
#define PIN_SIM_RESET 35
#define PIN_SOCKET_TX 27
#define PIN_SOCKET_RX 26
const char* ssid = "MiRed";
const char* password = "miPassword";
//NEO-M8N
const char* server = "your_server_ip";
const int serverPort = 8883;
//SIM7080G
const char* apn = "miAPN";
const char* user = "miUser";
const char* pass = "miPass";
//SIM7080G
SIMCOM sim(Serial1);
TinyGsmClient client(sim);
PubSubClient mqtt(client);
//NEO-M8N
//GPS
GPS gps;
//NEO-M8N
//GPS
void setupGPS(){
gps.begin(9600);
}
//NEO-M8N
//GPS
float getLat(){
return gps.getLat();
}
//NEO-M8N
//GPS
float getLng(){
return gps.getLng();
}
//SIM7080G