BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Local Server/Sim800L

Hy guys!

I have a big problem with my project and I hope you can help me! :slight_smile:
Hardware: Arduino Pro Mini + Sim800L + Battery
Info: “Local Server and app works fine for my other projects. (Arduinu UNO + Ethernet-Shild)”

I want to send Temp, Hum to my local blynk server, installed on a raspi!
Info: Sketch works fine with blynk cloud!
But if I use Local Blynk Server I get following information:

Modem init...
Connecting to network...
Network: T-Mobile A
Connecting to XXX
Connected to GPRS
Connecting to blynk-cloud.com:80
Invalid auth token

Sketch below:

#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800

#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>

char auth[] = "c5742898aa524b36b42ffe3d5f09695";
//char auth[] = "abd55e74180d4be8b2738e694dc66282";
  
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "XXX.ddns.net";
char user[] = "";
char pass[] = "";

#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX

TinyGsm modem(SerialAT);

#include <SoftwareSerial.h>
#include <Vcc.h>
const float VccMin   = 3.3;           // Minimum expected Vcc level, in Volts.
const float VccMax   = 4.1;           // Maximum expected Vcc level, in Volts.
const float VccCorrection = 1.0/1.018;  // Measured Vcc by multimeter divided by reported Vcc
Vcc vcc(VccCorrection);
int i = 0;

#include <avr/sleep.h> 
volatile int sleepcounter = 0; // Schlafzyklen mitzählen
int k=0;

#include <DHT.h>
#define DHTPIN 5     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature 


void setup()
{
  // Debug console
  Serial.begin(9600);
  pinMode(6, OUTPUT);
  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(3000);

  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  Serial.println("Initializing modem...");
  digitalWrite(6, HIGH);
  Serial.println("Setup High");
  delay(15000);
  
  modem.restart();

  // Unlock your SIM card with a PIN
  modem.simUnlock("2322");
  

Blynk.begin(auth, modem, apn, user, pass);

  dht.begin();

  watchdogOn(); // Watchdog timer einschalten.
//  ADCSRA = ADCSRA & B01111111; // ADC abschalten, ADEN bit7 zu 0
  ACSR = B10000000; // Analogen Comparator abschalten, ACD bit7 zu 1
  DIDR0 = DIDR0 | B00111111; // Digitale Eingangspuffer ausschalten, analoge Eingangs Pins 0-5 auf 
}

void loop()
{
  delay(2000);

//  if(Blynk.connected())
//  {
//    Blynk.run();
//    Serial.println("Blynk.run");
//  }
//  else
//  {
    digitalWrite(6, HIGH);
    Serial.println("Loop HIGH");
    delay(20000);
    modem.restart();
    Blynk.begin(auth, modem, apn, user, pass);
    delay(10000);
//  }
    
  float p = 0.0;
  float v = 0.0;
  v = vcc.Read_Volts();
  p = vcc.Read_Perc(VccMin, VccMax);
  Blynk.virtualWrite(V0, v);
  Blynk.virtualWrite(V1, p);
  Blynk.virtualWrite(V2, i);
  Serial.println(i);
  i++;
  delay(2000);
  //Read data and store it to variables hum and temp
  hum = dht.readHumidity();
  temp= dht.readTemperature();
  //Print temp and humidity values to serial monitor
  Serial.print("Humidity: ");
  Serial.print(hum);
  Serial.print(" %, Temp: ");
  Serial.print(temp);
  Serial.println(" Celsius");
  Blynk.virtualWrite(V3, hum);
  Blynk.virtualWrite(V4, temp);
  delay(2000); //Delay 2 sec.
  
  delay(10000);
  digitalWrite(6, LOW);
  Serial.println("Loop LOW");
  delay(1000);
  Serial.println("PWR D");
  delay(1000);
  pwrDown(600);
  
}

void pwrDown(int sekunden) 
{
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // den tiefsten Schlaf auswählen PWR_DOWN
  for(int i=0; i < sekunden; i++) {
    sleep_enable(); // sleep mode einschalten
    sleep_mode(); // in den sleep mode gehen
    sleep_disable(); // sleep mode ausschalten nach dem Erwachen
  }
}

void watchdogOn() 
{
  MCUSR = MCUSR & B11110111; // Reset flag ausschalten, WDRF bit3 vom MCUSR.
  WDTCSR = WDTCSR | B00011000; // Bit 3+4 um danach den Prescaler setzen zu können
  WDTCSR = B00000110; // Watchdog Prescaler auf 128k setzen > ergibt ca. 1 Sekunde
  WDTCSR = WDTCSR | B01000000; // Watchdog Interrupt einschalten
  MCUSR = MCUSR & B11110111;
}

ISR(WDT_vect) {
  sleepcounter ++; // Schlafzyklen mitzählen
}

I think I have some troubles with Blynk.begin() and hope someone can help me!

Thanks!

I fixed your posted code formatting as required in the Welcome Topic… [README] Welcome to Blynk Community!

Should be self explanatory… Double check that you are not missing or adding any extra characters in your Auth code.

Thank you very much for formatting, I will keep it in my mind!

But back to my problem: :slight_smile:
Why is the project connecting to the Blynk cloud, not to my local blynk server?

Thx

You sketch will connect to whatever server you explicitly tell it to… Your posted code is not specifying any such Local Server.

Since you say you have used your Local Server before, you should know what to do for this code… But perhaps you need to do that from the Sim800, I have not used such so do not know :thinking:

As for the Auth code, each server is independent of all others, so you will need to use the correct AUTH code, generated by the server that hosts whatever project you are connecting to.

Thank you very much Gunner! I found the fault. I have to define char server[] = “XXXX.ddns.net”;
And so it works.
Thx

1 Like