BLYNK
BLYNK.IO       📲 GETTING STARTED       đź“— DOCS       âť“HELP CENTER       👉 SKETCH BUILDER

Syntax Error on #define BLYNK_TEMPLATE_ID when running any script

Hello,
I am new to Blynk - I have been searching a way around this issue - which I may have triggered myself? -:

node terminal.index.js 

/home/pi/asmv-module/terminal.index.js:11
#define BLYNK_TEMPLATE_ID "TMPLOPZp_sO3"
^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:760:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
    at internal/main/run_main_module.js:21:11

Hardware model: RPiZeroW
Communication type: Wifi
Smartphone OS Android
Blynk server (cloud)
Blynk Library version
node -v :v11.15.0
npm -v : 7.20.5
asmv-module@1.0.0 /home/pi/asmv-module
├── blynk-library@0.5.4
└── onoff@6.0.3

I have declared all virtual pin, created my template, etc…
I tried to run the Terminal example from Blynk Examples

Any idea what I am doing wrong ?

ps: tried the blynk-client Auth but I need TCP, it is nt going through and same issue with TCP script it triggers a syntax error.
pps: packages were installed global -g and then created the project directory and npm init the project directory and requested blynk and onoff package locally in project directory.

/*************************************************************

  You can send/receive any data using WidgetTerminal object.

  App project setup:
    Terminal widget attached to Virtual Pin V1
 *************************************************************/

// Template ID and Device Name are provided by the Blynk.Cloud.
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID           "TMPLOPZp_sO3"
#define BLYNK_DEVICE_NAME           "ASMV 001"
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Comment this out to disable prints and save space
#define BLYNK_PRINT stdout

#ifdef RASPBERRY
 #include <BlynkApiWiringPi.h>
#else
 #include <BlynkApiLinux.h>
#endif
#include <BlynkSocket.h>
#include <BlynkOptionsParser.h>

static BlynkTransportSocket _blynkTransport;
BlynkSocket Blynk(_blynkTransport);
#include <BlynkWidgets.h>

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("Marco") == param.asStr()) {
    terminal.println("You said: 'Marco'") ;
    terminal.println("I said: 'Polo'") ;
  } else {

    // Send it back
    terminal.print("You said:");
    terminal.write(param.getBuffer(), param.getLength());
    terminal.println();
  }

  // Ensure everything is sent
  terminal.flush();
}

void setup()
{
  // Clear the terminal content
  terminal.clear();

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type 'Marco' and get a reply, or type"));
  terminal.println(F("anything else and get it printed back."));
  terminal.flush();
}

void loop()
{
  Blynk.run();
}

int main(int argc, char* argv[])
{
  const char *auth, *serv;
  uint16_t port;
  parse_options(argc, argv, auth, serv, port);

  Blynk.begin(auth, serv, port);

  setup();
  while(true) {
    loop();
  }

  return 0;
}

and

blynk-client XXXXXXXXXXXXXXX

    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/

  Give Blynk a Github star! => https://github.com/vshymanskyy/blynk-library-js

OnOff mode
Connecting to: blynk-cloud.com 443
SSL authorization...
SSL not authorized

use triple backticks or else pete sir will remove it

You’re combining new Blynk version 2 with Blynk Legacy (version 1) code and als using old Legacy Blynk library.

Hi bazzio,
I am new. ok I can of understood that Blynk has changed somehow - albeit unclear for me.
And I guess I need to use version 2 code ?
Are the https://examples.blynk.cc/ not Blynk version 2 or are they version 1?
where to find version 2 samples?

Hi, you can find the latest version of the library at the link - Releases · blynkkk/blynk-library · GitHub,
and examples from the link - blynk-library/examples at master · blynkkk/blynk-library · GitHub

And documentation:
https://docs.blynk.io/en/

@rfv-370 please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Hi Pete,
I thought I did… does it not display correctly

Hi DimitryPB,
thank you. So if I understand well the
├── blynk-library@0.5.4
└── onoff@6.0.3
will not work with the new cloud Blynk, is this correct?

But npm does not provide any newer librairy of blynk to install…
and
when checking - I do have the latest available from node.js .

Any work around to force the upgrade with node.js npm ?

and/or is blynk-library@0.5.4 works with the new Blyn cloud server at all?

Further I looked at
[Prepare Your Code - Blynk Documentation]
but nothing about Raspberry P…i and the link for library installation is inactivated:

And here as well nothing on how to install the new libarary :slight_smile:
https://github.com/blynkkk/blynk-library/releases

Any idea on how to have the new blynk on the raspberry pi?

Or with RaspberryPi we need to revet to the old Blynk.cc ?

It does now.

Pete.

For all Newbies on Blynk with a Raspberry Pi ( Rpi ):
There are 2 Blynk (s):
The old Blynk , and
The New Blynk - - which is referred to as " Blynk 2.0 " or Blynk 2
The new Blynk is Blynk.io (Blynk 2.0) - which has its own IOS/Android App as well as a web interface which you need to signup
The old Blynk is Blynk.cc. with its own (different) App IOS/Android.

  • I know for a newbie it can be confusing… it was for me…-

Just take note that the old Blynk (blync.cc) might be discontinued (my understanding?) and that new Blynk 2 is not yet working on Raspberry Pi ( RPi) with node.js (my experience).

The only way for now - August 2021 - to have a Raspberry Pi to connect to Blynk 2 (Blynk.io) is to use the Python Library according the forum :
https://community.blynk.cc/t/micropython-and-blynk-2-0-libary/53861/18

I hope it will help others with Rapsberry Pi s in case you need.

This thread can be closed I guess. - or updated with a date of availability of the node.js / npm availability of the blynk-library (2.0) updates… @BlynkTeam ?

@rfv-370 I think you might have confused things further!

Old Blynk
Known as Blynk Legacy or Blynk 0.1
Not developed for over 2 years and no longer supported.
New sign-ups to Blynk Legacy will probably be stopped in the future and the system will be retired evebtually.

New Blynk
Known as Blynk IoT or Blynk 2.0
Both Blynk.cc and Blynk.io will take you to the Blynk IoT website where you can sign-up for an account.

Personally, I don’t like the RPI as a Blynk client. It’s expensive, slow to boot, requires a beefy power supply, needs the OS installing and updating regularly and is prone to SD card failures.
You’re generally much better off with a NodeMCU or ESP32 as your Blynk client device and using C++ as your programming language (most of the examples are in C++ because this is the route most people take).

If you do use an RPI then its probably better to do what I do.
I use NodeMCU and ESP32 clients running non-Blynk code, communicating with an RPI running Node-Red.
Communication is via MQTT and the RPI runs a Mosquitto MQTT broker. A Node-Red plug-in is used to talk to Blynk, giving the mobile app capability.
If you wanted to use the same RPI as a client then I guess you could do this in Node-Red, without any Blynk client library, by using the Node-Red RPI GPIO in/out nodes within Node-Red.

Pete.

@PeteKnight

Thank you for your help to clarify things.

The node-red plugin you mentionned, is it this one ?
https://flows.nodered.org/node/node-red-contrib-blynk-ws

This node-red plugin is Blynk 2 compatible?

If so, you are right from node-red to blynk to mobile App. This would be nice.

Best

No, that’s the legacy one.

The Blynk IoT one is called node-red-contrib-blynk-iot

Pete.

Thanks.
I guess I got it:
https://flows.nodered.org/node/node-red-contrib-blynk-iot

You should read this, to better understand what works and what doesn’t in this new contrib…

Pete.