Sublime Forum

Arduino Sublime NodeMCU issue on macOS

#1

Hello! I have a simple script for DHT11 sensor working with Cayenne ioT.

"#define CAYENNE_DEBUG
"#define CAYENNE_PRINT Serial
"#include <CayenneMQTTESP8266.h
"#include <DHT.h

char ssid[] = “xxxxxxxxxxxxxxx”;
char wifiPassword[] = “xxxxxxxxxxxxx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “xxxxxxxxxxxxxxx”;
char password[] = “xxxxxxxxxxxxxxx”;
char clientID[] = “xxxxxxxxxxxxxxx”;

DHT dht(D2, DHT11);

void setup() {

Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(2,OUTPUT);
digitalWrite(2,HIGH);
}

void loop() {
Cayenne.loop();
float temp = dht.readTemperature();
float hum = dht.readHumidity();
Cayenne.virtualWrite(1, temp, TYPE_TEMPERATURE, UNIT_CELSIUS);
Cayenne.virtualWrite(2, hum, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
}

CAYENNE_IN(0)
{
digitalWrite(2, getValue.asInt());
}

Here are my settings for board, programmer, build etc…

I can without any problem compile and upload this sketch with Arduino IDE but Sublime throws at me these errors:

[96.1%] Compiling uart.c…
[97.4%] Compiling cont.S…
[98.7%] Linking everything together…
[100.0%] Creating binary files…
/Users/raf/Library/Arduino15/build/ESP8266new/arduino.ar(CayenneMQTTClient.c.o):(.text.MQTTMessageArrived+0x4): undefined reference to CayenneParseTopic' /Users/raf/Library/Arduino15/build/ESP8266new/arduino.ar(CayenneMQTTClient.c.o):(.text.MQTTMessageArrived+0x8): undefined reference toCayenneParsePayload’
/Users/raf/Library/Arduino15/build/ESP8266new/arduino.ar(CayenneMQTTClient.c.o): In function MQTTMessageArrived': /Users/raf/Documents/Arduino/libraries/Cayenne-MQTT-ESP/src/CayenneMQTTClient/CayenneMQTTClient.c:386: undefined reference toCayenneParseTopic’
/Users/raf/Documents/Arduino/libraries/Cayenne-MQTT-ESP/src/CayenneMQTTClient/CayenneMQTTClient.c:386: undefined reference to CayenneParsePayload' /Users/raf/Library/Arduino15/build/ESP8266new/arduino.ar(CayenneMQTTClient.c.o):(.text.CayenneMQTTPublishDataArray+0x4): undefined reference toCayenneBuildTopic’
/Users/raf/Library/Arduino15/build/ESP8266new/arduino.ar(CayenneMQTTClient.c.o):(.text.CayenneMQTTPublishDataArray+0xc): undefined reference to CayenneBuildDataPayload' /Users/raf/Library/Arduino15/build/ESP8266new/arduino.ar(CayenneMQTTClient.c.o): In functionCayenneMQTTPublishDataArray’:
/Users/raf/Documents/Arduino/libraries/Cayenne-MQTT-ESP/src/CayenneMQTTClient/CayenneMQTTClient.c:386: undefined reference to CayenneBuildTopic' /Users/raf/Documents/Arduino/libraries/Cayenne-MQTT-ESP/src/CayenneMQTTClient/CayenneMQTTClient.c:386: undefined reference toCayenneBuildDataPayload’
/Users/raf/Documents/Arduino/libraries/Cayenne-MQTT-ESP/src/CayenneMQTTClient/CayenneMQTTClient.c:386: undefined reference to CayenneBuildResponsePayload' /Users/raf/Library/Arduino15/build/ESP8266new/arduino.ar(CayenneMQTTClient.c.o): In functionCayenneMQTTPublishResponse’:
/Users/raf/Documents/Arduino/libraries/Cayenne-MQTT-ESP/src/CayenneMQTTClient/CayenneMQTTClient.c:386: undefined reference to CayenneBuildTopic' /Users/raf/Documents/Arduino/libraries/Cayenne-MQTT-ESP/src/CayenneMQTTClient/CayenneMQTTClient.c:386: undefined reference toCayenneBuildResponsePayload’
/Users/raf/Library/Arduino15/build/ESP8266new/arduino.ar(CayenneMQTTClient.c.o): In function CayenneMQTTSubscribe': /Users/raf/Documents/Arduino/libraries/Cayenne-MQTT-ESP/src/CayenneMQTTClient/CayenneMQTTClient.c:386: undefined reference toCayenneBuildTopic’
/Users/raf/Library/Arduino15/build/ESP8266new/arduino.ar(MQTTClient.c.o): In function `MQTTClientInit’:
/Users/raf/Documents/Arduino/libraries/Cayenne-MQTT-ESP/src/CayenneMQTTClient/MQTTClient.c:586: undefined
etc…
etc…
etc…

/ reference to `MQTTSerialize_disconnect’
collect2: error: ld returned 1 exit status
[Build] Error occurred.

The weird thing is that same sketch would perfectly work with Arduino IDE and AND any other sketch that uploaded on Board Uno also works without any problem. The issue triggers when building sketch for NodeMCU.

Any IDEAS???
Thank you in advance for any help!

0 Likes

#2

I don’t know from Arduino things, but the error you’re getting is a link error about missing symbols, so my first avenue of investigation would be to review the command that it’s running to see if it’s including an appropriate library on the link line.

0 Likes

#3

Thank you for an idea. But is that usual that Sublime require different code for the same command? Do they have different compilers with Arduino IDE or something?Is it normal?

0 Likes

#4

In most cases the command can be the same. In some rare cases you command need to be a little different due Sublime Text does not emulate a full featured terminal, you may need to change you command into making Sublime Text to launch a new terminal. See the issue: https://github.com/SublimeTextIssues/Core/issues/1468 (Full/complete terminal features on Sublime Text) for reference.

But this does not seen to be your case. The probable problem is that Sublime Text is not nice into interpreting your command, so what is the command you run on the command line and what is the contents of your .sublime-build file?

Usually the changes required are like this; on the command line you can type cd mydir, but on Sublime Text you need to enter ["cd", "mydir"].

You may look into these links for reference:

  1. http://docs.sublimetext.info/en/latest/reference/build_systems.html
  2. https://www.sublimetext.com/docs/3/build_systems.html
0 Likes

#5

For that you’d have to ask whoever wrote the package/build system that you’re using, but it’s entirely possible in the general case that building different software using different features would require extra libraries and tooling for support code.

For example, the library that provides the CayenneParsePayload function/method/class may not be required for all programs, so not linking with it works just fine in those cases but causes problems for programs that need it.

Whether that applies here or not, I don’t know since I’m not an Arduino guy. Do programs that work fine also use whatever Cayenne is?

0 Likes

#6

Thank you for being helpful, first of all!
Now, after spending 3hrs looking for .sublime-build file :slight_smile: (I’m more of an electronic sider, not developer) I finally found out that I don’t even have these files in my SublimeText3 folder(yup, I know they are hidden). So after a short research i found this little nice add-on https://github.com/bepursuant/SublimeNodeMCU and merged it to my SublimeText3/User folder, changing the content of .sublime-build file to this

{
“shell_cmd”: ““python” -u “$packages/User/SublimeNodeMCU/SublimeNodeMCU.py” “$file””,
“file_regex”: “^(.\.lua):([0-9]):”,
“syntax”: “Packages/Lua/Lua.tmLanguage”,
}

And checked the builder as NodeMCU

After another building try with F7 , I got this error:

/Users/raf/.bash_profile: line 8: hub: command not found
[SublimeNodeMCU] Uploading…
Opening serial port COM4:115200…Traceback (most recent call last):
File “/Users/raf/Library/Application Support/Sublime Text 3/Packages/User/SublimeNodeMCU/SublimeNodeMCU.py”, line 113, in
ser = serial.Serial(port, baud, timeout=1)
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/serial/serialutil.py”, line 282, in init
self.open()
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/serial/serialposix.py”, line 289, in open
self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)
OSError: [Errno 2] No such file or directory: ‘COM4’
[Finished in 0.9s with exit code 1]
[shell_cmd: “python” -u “/Users/rafik/Library/Application Support/Sublime Text 3/Packages/User/SublimeNodeMCU/SublimeNodeMCU.py” “/Users/rafik/Desktop/ESP8266new/ESP8266new.ino”]
[dir: /Users/raf/Desktop/ESP8266new]
[path: /Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/Users/rafik/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS]

I noticed that in file SublimNodMCU.py, port was set as COM4
I wanted to add image but As a new user I can upload only one image at a time…

but my port is /dev/cu.wchusbserial1d1140 and I will most probably to change it with your help(Do I have to simply copy/paste my port’s name instead of COM4?).
But still… I don’t even have to think now about uploading because I am not even successful in building a proper load.

Any ideas?

0 Likes

#7

here is it

0 Likes

#8

That’s a point. Everything is working perfectly but NodeMCU. And since almost all of my projects are based on smart home base, Cayenne ioT libraries and NodeMCU used in all of these projects. And when i am trying to build, Sublime simply gets confused with all these Cayenne libraries .

Since it was mentioned by you, that some libraries may not be required and some of them actually may, I think there is some kind of conflict or misallocation between Arduino and Sublime folders, cause Sublime getting these files from Arduino folders.

0 Likes

#9

It seems to be working correctly, you should change the port to it to an valid one. Now I do not know how the port should be named. You can try just put /dev/cu.wchusbserial1d1140 or COM1, 2, 3.

Outside Sublime Text, what is the command you run to build it?

0 Likes

#10

Sorry, I don’t really understand your question. I use only GUI IDEs for coding. I never use a terminal. In these IDE’s it’s a simple button for building or uploading sketches.
I have a feeling I will code sketches on Sublime and upload/ compile them on Arduino :smirk:

0 Likes

#11

For Sublime Text, you will need to know what is the command your IDE is running or what it is doing, so only then you can do the same thing within Sublime Text.

Usually the easy way is to create a shell script which do the building and call it from your Sublime Text build system. Sublime Text is just a plain text editor. By himself it does not have integrated extra nice IDE feature support.

In order to do the same thing you do in a usual IDE, you need to know what the IDE is doing behind the scenes and implement the same thing for Sublime Text.

If you are lucky, someone already had implemented it for Sublime Text, then you just need to figure out how to use. On this case, is seems that the package SublimeNodeMCU was already implemented and could help you. But unfortunately it does not seem to be very easy to use as you cannot figure out what is the COM port you should use, or perhaps it is not even working on MAC OS because the original author could have written it using the Windows, and it still not working for other platforms.

If you cannot make it work, I would suggest to you use Sublime Text to write the code, and keep you IDE open only for building the code. This is what I currently do while programming in Java, because until now I could not figured out how to make Sublime Text build any java code without make me writing an Ant or Maven build script, or building a fully complicated javac command line.

You can try to open an issue on the SublimeNodeMCU package issue tracker https://github.com/bepursuant/SublimeNodeMCU/issues perhaps the original author can help.

0 Likes

#12

Thanks a lot. I guess that’s exactly what I am going to do.

0 Likes