Mapple mini
/*
This example shows how to connect to Cayenne using a GSM device and send/receive sample data.
The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
1. Install the TinyGSM library (https://github.com/vshymanskyy/TinyGSM) from the Arduino Library Manager.
2. Set the Cayenne authentication info to match the authentication info from the Dashboard.
3. Uncomment the correct GSM modem type and set the GSM connection info, if needed.
4. Compile and upload the sketch.
5. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/
//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
// Uncomment your modem type:
#define TINY_GSM_MODEM_SIM800
// #define TINY_GSM_MODEM_SIM808
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_UBLOX
// #define TINY_GSM_MODEM_BG96
// #define TINY_GSM_MODEM_A6
// #define TINY_GSM_MODEM_A7
// #define TINY_GSM_MODEM_M590
// #define TINY_GSM_MODEM_ESP8266
// #define TINY_GSM_MODEM_XBEE
#include <CayenneMQTTGSM.h>
#include <OneWireSTM.h>
#include <EEPROM.h>
// This sketch uses a software serial connection.
//#include <SoftwareSerial.h>
//SoftwareSerial gsmSerial(2, 3); // RX, TX
// If you are using a device that supports a hardware serial (Mega, Leonardo, etc.) and prefer to use
// that you can comment out the above lines and uncomment the one below.
#define gsmSerial Serial1
//ST_CP 74HC595
#define latchPin PC14
//SH_CP 74HC595
#define clockPin PC15
//DS 74HC595
#define dataPin PC13
// GSM connection info.
char apn[] = "internet"; // Access point name. Leave empty if it is not needed.
char gprsLogin[] = ""; // GPRS username. Leave empty if it is not needed.
char gprsPassword[] = ""; // GPRS password. Leave empty if it is not needed.
char pin[] = ""; // SIM pin number. Leave empty if it is not needed.
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
unsigned long lastMillis=0;
OneWire ds(PA0); // (a 4.7K resistor is necessary)
byte dsAdr[6]={0,0,0,0,0,0};
unsigned char dsAdrIndx=0;
uint16 dataWrite = 0xAA;
uint16 dataRead = 0xAA;
uint16 addressWrite = 0x10;
uint16 temp=0;
struct secureSwitchData
{
unsigned char pre=0xAA;
unsigned char state=0;
int voltage[3];
int current[3];
float temperature[3][6];
int relays[3][3] = {{0, 0, 0},{0, 0, 0},{0, 0, 0}};
};
secureSwitchData sSD;
void setup() {
Serial.begin(9600);
// Auto-detect the GSM serial baud rate. You can manually set it instead if you want to save a bit of space.
TinyGsmAutoBaud(gsmSerial);
Cayenne.begin(username, password, clientID, gsmSerial, apn, gprsLogin, gprsPassword, pin);
STR();
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Cayenne.virtualWrite(5, sSD.relays[0][0]&(1<<0));
delay(500);
Cayenne.virtualWrite(6, sSD.relays[0][0]&(1<<1));
delay(500);
Cayenne.virtualWrite(7, sSD.relays[0][0]&(1<<2));
delay(500);
Cayenne.virtualWrite(8, sSD.relays[0][0]&(1<<3));
delay(500);
Cayenne.virtualWrite(9, sSD.relays[0][0]&(1<<4));
delay(500);
Cayenne.virtualWrite(15, sSD.relays[0][1]&(1<<0));
delay(500);
Cayenne.virtualWrite(16, sSD.relays[0][1]&(1<<1));
delay(500);
Cayenne.virtualWrite(17, sSD.relays[0][1]&(1<<2));
delay(500);
Cayenne.virtualWrite(18, sSD.relays[0][1]&(1<<3));
delay(500);
Cayenne.virtualWrite(19, sSD.relays[0][1]&(1<<4));
delay(500);
Cayenne.virtualWrite(25, sSD.relays[0][2]&(1<<0));
delay(500);
Cayenne.virtualWrite(26, sSD.relays[0][2]&(1<<1));
delay(500);
Cayenne.virtualWrite(27, sSD.relays[0][2]&(1<<2));
delay(500);
Cayenne.virtualWrite(28, sSD.relays[0][2]&(1<<3));
delay(500);
Cayenne.virtualWrite(29, sSD.relays[0][2]&(1<<4));
delay(500);
PUSH_SHIFT_REGS (sSD.relays[0][0]|(sSD.relays[0][1]<<5)|(sSD.relays[0][2]<<10));
Serial.println("sSD.relays start");
Serial.println(sSD.relays[0][0],BIN);
Serial.println(sSD.relays[0][1],BIN);
Serial.println(sSD.relays[0][2],BIN);
}