XDUSS
February 18, 2018, 7:07pm
1
• My device Arduino Mega with Ethernet Shield W5100
PS. Sorry for my English…
Hi. How i can use arduino (+blynk) when without internet connection?
My program ends with “Blynk.begin”…
I managed to bypass it (code below) and everything works with and without Internet.
I would like if run arduino without internet,
then it connect to the blynk network immediately after detecting the connection to the Internet.
Code:
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
char auth[] = "xxx"; // Auth Token od Blynk
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
#define W5100_CS 10 //Ethernet shield pin
#define SDCARD_CS 4 //SDcard pin
BlynkTimer timer;
void setup()
{
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
Ethernet.begin(mac);
Blynk.config(auth);
if(Blynk.connect()){
Serial.println("Connect");
} else Serial.println("No connect");
timer.setInterval(600000L, reconnect);
}
void loop()
{
if(Blynk.connected()){
Blynk.run();
}
Serial.println("Work");
timer.run();
}
void reconnect(){
if(!Blynk.connected()){
Ethernet.begin(mac);
Blynk.connect(1000);
} else Serial.println("Connect OK");
}
Ok the code works (UP).
I have edited this post, maybe someone will need it.
Gunner
February 18, 2018, 7:42pm
2
As per the directions, that you deleted in-order to post your topic… I have formatted your code for proper viewing.
Search this forum for other examples of functioning code without internet connection… many topics about this issue already.
XDUSS
February 18, 2018, 8:36pm
3
For the needs of the project, I was editing the timeout in the Ethernet.h library so that the waiting time was not that long and other functions were running smoother.
timeout = 2000 (default 30000)
responseTimeout = 1000 (default 5000)
Ethernet.h file:
#ifndef ethernet_h
#define ethernet_h
#include <inttypes.h>
//#include "w5100.h"
#include "IPAddress.h"
#include "EthernetClient.h"
#include "EthernetServer.h"
#include "Dhcp.h"
#define MAX_SOCK_NUM 4
class EthernetClass {
private:
IPAddress _dnsServerAddress;
DhcpClass* _dhcp;
public:
static uint8_t _state[MAX_SOCK_NUM];
static uint16_t _server_port[MAX_SOCK_NUM];
// Initialise the Ethernet shield to use the provided MAC address and gain the rest of the
// configuration through DHCP.
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
int begin(uint8_t *mac_address, unsigned long timeout = 2000, unsigned long responseTimeout = 1000);
void begin(uint8_t *mac_address, IPAddress local_ip);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
int maintain();
IPAddress localIP();
IPAddress subnetMask();
IPAddress gatewayIP();
IPAddress dnsServerIP();
friend class EthernetClient;
friend class EthernetServer;
};
extern EthernetClass Ethernet;
#endif
Gunner
Split this topic
August 18, 2018, 3:32am
4
Gfarid
July 20, 2019, 2:09pm
5
I want to do the same thing but new library 0.6.1 has different Ethernet.h . Could you help me to update accordingly.