Doubts to flash NodeMCU + Garden Project

I am using the code and app of this link Simple 4 relay irrigation scheduler but I have doubts about how to flash the code inside my sonoff. I copy the code, I input my token, my ssid and password but I also have static ip in my router, then I don’t know how to fix a static it in the code.

Thks n brgds

I think you need to explain this bit in more detail.
Do you mean you have a static public IP address, or that you want the Sonoff to allows use the same IP within your home network?

If you router is using DHCP to hand-out IP addresses to devices on your network then the easiest solution is to allocated a fixed IP address to your Sonoff in your router. When the Sonoff requests an IP address from the router’s DHCP server it will then be given the one you’ve specified.

Pete.

Hi Pete,

Thks for your reply. I have a network with static ip. I do that in each device less in one laptop that I used the MAC address to fic a static ip from the router. The problem is I cannot find the MAC address for my sonoff.
Also I want to know if I can use 5Ghz network for my iPhone and to connect sonoff to 2.4 ghz the sonoff.

I use this command to a Display Widget in this example sketch…

Blynk.virtualWrite(V3, WiFi.macAddress());

If your phone and router support 5Ghz, then no problem.

But all ESP based devices ONLY use 2.4Ghz, so your router needs to support BOTH at same time in-order to work/share properly across the bands

WiFi router is a Apple Extreme, then no problem to run both freq. at same time.

I found how to fix static IP inside code with following:

//IPAddress server_ip (192, 168, 10, 1);

// Mac address should be different for each device in your LAN
// byte arduino_mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
IPAddress sonoff_ip ( 192, 168, 10, 88);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip ( 192, 168, 10, 1);
IPAddress subnet_mask(255, 255, 255, 0);

But I don’t know the IP for //IPAddress server_ip and neither the MAC address.

you can ping blynk-cloud.com for that.

You should be able to Google ways to read MAC addresses from various ESP based devices.

You should be also able to isolate your routers connected DHCP devices and figure out which one is your Sonoff.

But if you can’t do that, then as already shown, you many need to load in another example sketch, like what I provided or make something up on your own… it need not be Blynk related, but then will need a WiFi library… and read the devices MAC address with the listed command WiFi.macAddress()

Here’s a bit of code thrown together from something I was doing earlier…

#include <ESP8266WiFi.h>

// Wi-Fi & Networking variables...
const char *ssid =      "xxx";      
const char *pass =      "xxx";
IPAddress ip            (192,168,10,88);              // Static IP Address for the device
IPAddress gateway       (192,168,10,1);
IPAddress subnet        (255,255,255,0);

void setup()
{
  Serial.begin(74880);
  WiFi_Connect(); // Connect to Wi-Fi
}


void WiFi_Connect()
{
  Serial.print(F("Connecting to Wi-Fi"));
  
  WiFi.begin(ssid, pass);
  WiFi.config(ip, gateway, subnet);
  WiFi.mode(WIFI_STA);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println(F(" CONNECTED"));
  Serial.println();
  

  Serial.print(F("MAC Address:           "));
  Serial.println(WiFi.macAddress());
    
} // End of void WiFi_Connect

void loop()
{
}

Use the MAC address that it gives to set a static IP in your router, then DON’T specify MAC address, or device IP in your code.

Pete.

Thks both. This week I have holidays, then I will try to do it. I hope I was able to success :slight_smile:

Hello,

I copy your code on ATOM and I added below lines to connect as static IP.

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “my token”;

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “my ssid”;
char pass[] = “my password”;

IPAddress server_ip (XXXXXX);

// Mac address should be different for each device in your LAN
// byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress sonoff_ip ( x, x, x, x);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip ( x, x, x, x);
IPAddress subnet_mask (255, 255, 255, 0);

When I try to Make Run I got following error:

gcc-make-run: Compile Error
TEST:1: *** missing separator. Stop.

Any Idea? If I only copy your code I get the same error.

Thks n brgds

First of all, you need to go back and edit your last post (using the pencil icon at the bottom) and format your code correctly. You’ve used “quote” and “unquote” where you should be using triple backticks - like this:
Blynk%20-%20FTFC

Secondly, you’re missing a comma between the third and fourth "x"s here:

IPAddress gateway_ip ( x, x, x x);

Thirdly, this is illegal:

IPAddress server_ip (blynk-cloud.com);

When you’ve corrected the formatting of your code I’ll tell you what you should use instead.

Pete.

By the way, please don’t post the same question on multiple topics.

I’ve deleted your identical post from this topic:

Keep your questions on this subject within this topic please.

Pete.

Sorry, now already updated.

I have the code in the Atom project saved as text. Then I click with right mouse button and I try to run giving above mentioned error.

I am a total rockie in this matter, I’m lost.

It was still wrong, you used apostrophes instead of backticks. I’ve fixed if for you now, but you need to figure it out for the future.

You need to replace:

IPAddress server_ip (blynk-cloud.com);

with

const char server_ip [] =   "blynk-cloud.com";

If you’re a rookie then I’d suggest that you drop the ATOM IDE and go for the Arduino IDE instead. It’s what the vast majority of community members use you’ll find it much easier to get community support that way.

I’m still confused about why you don’t just set-up your router to have a small range of DHCP addresses and get up and running that way.

Pete.

The reason to use static ip’s is because I have all my devices with static ip including my NAS.
I bought a sonoff ch4 pro in order to do a irrigation system. I already have it ready to flash new firmware which should be in BIN extension.
I copy one of the above projects and I added just the ip lines to make it static. I used Atom to do that. Now once finished I think I have to compile it in order to use it to flash the sonoff, but I am doing something wrong or I missed some step.
I am trying to find it in google but I was not able to find all steps to compile above text.
If someone can support me or can tell me where to find more info I will appreciate.

Hi Pete. Finally I did. I used Arduino IDE with one sketch posted here. I selected my board ESP8266 and I compiled. Tomorrow I will try to flash my sonoff and I will test it.

Thks a lot, I was try Atom when sketch is wonderful and easier.

I will let you know final result.

1 Like

Hello. I don’t know the reason but my sonoff CH4 Pro is well flashed at 100% but when I try to star it, it do a knock noise and blue light doent star. Maybe I did something wrong.

I am thinking to buy a Arduino board and some relays. Any special brand/model to work with this sketch?

Thks

Did you flash it in the correct mode?
Is it connecting to your wi-fi and Blynk server?
What serial output are you getting?

If you’re going for different hardware (I’d stick with getting the Sonoff working if I were you) then before you rush out and buy an Arduino you should read this:

Pete.

Thks for your help I am thinking this set

The problem with sonoff is you have to trick it and maybe I did something wrong.

Did you read the link I gave you?
Do you realise that the product you’re thinking of buying has no wired or wireless internet connection capability as it stands?

Vyou do t have to “trick” the Sonoff, you have to replace the existing firmware with your own firmware, by uploading a new sketch to it. This is exactly the same as you would have to do with any other device you chose to use.

If you’re not happy to answer questions on what flash settings you used, whether the device is connecting to Blynk and what serial output you’re getting then I’ll step back and let you do your own thing.

Pete.

Hi Pete. I read your link. Interesting. The problem of sonoff is that you hace to weld some cable in the chip and I don’t know I did property. Arduino IDE confirm 100% flashing but when I connect sonoff is not doing anything.
This is the reason why I am thing to buy an Arduino board with WiFi + relays in otprder to connect my garden irrigation Solenoid and control it from my mobile.
I think I replied all your question.