Skip to content

Instantly share code, notes, and snippets.

@Resousse
Created January 17, 2021 13:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Resousse/c5293bb208f88a3de5e0e7178fec615c to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include <SPI.h>
#include <ArduinoLowPower.h>
#include <Ethernet.h>
#include <SigFox.h>
byte mac[] = {0x9F, 0xAF, 0xDF, 0x0F, 0xAF, 0x7F};
EthernetClient client;
unsigned long previousMillis = 7000000;
unsigned long interval = 300000L;
char erreur = 0;
unsigned long previousfox = 9000000;
unsigned long intervalfox = 630000L;
void setup()
{
Serial.begin(9600);
delay(1000);
if (!SigFox.begin())
{
Serial.println("Shield error or not present!");
}
else
{
SigFox.debug();
String version = SigFox.SigVersion();
String ID = SigFox.ID();
String PAC = SigFox.PAC();
Serial.println("MKRFox1200 Sigfox first configuration");
Serial.println("SigFox FW version " + version);
Serial.println("ID = " + ID);
Serial.println("PAC = " + PAC);
Serial.println("");
SigFox.end();
}
}
void loop()
{
char erreur = 0;
if ((unsigned long)(millis() - previousfox) >= intervalfox)
{
SigFox.begin();
delay(100);
//SigFox.status();
//delay(1);
SigFox.beginPacket();
SigFox.print("OK");
int ret = SigFox.endPacket();
if (ret > 0)
{
Serial.println("No Sigfox transmission");
}
else
{
Serial.println("Transmission Sigfox ok");
}
//Serial.println(SigFox.status(SIGFOX));
//Serial.println(SigFox.status(ATMEL));
SigFox.end();
previousfox = millis();
}
if ((unsigned long)(millis() - previousMillis) >= interval)
{
erreur = Ethernet.begin(mac);
if (erreur == 0)
{
Serial.println("Erreur pas de DHCP");
}
else
{
erreur = client.connect("hc-ping.com", 80);
if (erreur == 1)
{
Serial.println("Connexion réseau OK");
client.println("GET /idJobxxxxx HTTP/1.1");
client.println("Host: hc-ping.com");
client.println("Connection: close");
client.println();
}
else
{
Serial.println("Erreur lors de l'envoi");
}
}
previousMillis = millis();
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment