bepursuant / SublimeNodeMCU

A Sublime3 plugin to quickly and easily upload files to a NodeMCU/ESP8266.
7 stars 0 forks source link

Arduino Sublim NodeMCU issue macOS #4

Open Rafiki22 opened 6 years ago

Rafiki22 commented 6 years ago

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());
}

I added this nice little SublimeNodeMCU script and edited SublimeNodeMCU.py

import os, serial, sys

# These settings will control how the script interacts with your NodeMCU. The defaults
# are sensible, but you will likely need to adjust them for your specific computer.
# 
port = '/dev/cu.wchusbserial1d1140'   #the COM port to which the NodeMCU is connected
baud = 115200     #usually 9600 or 115200

reset = True    #automtically reset the NodeMCU before writing
execute = True  #automatically execute uploaded file after upload

verbose = True  #write debugging information to the console

prompt = b'\n> '#this is the prompt we will wait for at times

ack = b'Y'      #this is the ack character from the receive script

and SublimeNodeMCU.sublime-build files:

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

But I have feeling I am missing something. After pressing F7 I am getting this error:

/Users/raf/.bash_profile: line 8: hub: command not found
[SublimeNodeMCU] Uploading...
Opening serial port /dev/cu.wchusbserial1d1140:115200...ok!
Reset...

and building simply stops.

Any ideas ??? Thank you in advance!

bepursuant commented 6 years ago

Hi Rafiki,

This was actually developed on a Windows box, and was not tested on MacOS, so it's possible it may need some slight adjustments to work in that environment.

It looks like it's opening the COM port, issuing a Reset, then just waiting for a prompt from the NodeMCU...

Please try changing the "Reset" parameter to False, you might not need the additional Reset command.

If that doesn't work, it might be an encoding thing when awaiting the prompt, so it might take a little troubleshooting. Unfortunately I don't use the lua framework for NodeMCU anymore (nor sublime), though I'd be happy to help troubleshoot and make a patch.

Rafiki22 commented 6 years ago

Hello be pursuant! Thank you for reply! After changing Reset to False, I got this message :

/Users/raf/.bash_profile: line 8: hub: command not found
[SublimeNodeMCU] Uploading...
Opening serial port /dev/cu.wchusbserial1d1140:115200...ok!
If nothing happens, try setting reset = True in SublimeNodeMCU.py
Traceback (most recent call last):
  File "/Users/raf/Library/Application Support/Sublime Text 3/Packages/User/SublimeNodeMCU/SublimeNodeMCU.py", line 127, in <module>
    sendReceiveScript(ser, filename);   #send receive script to NodeMCU to get ready to receive data
  File "/Users/raf/Library/Application Support/Sublime Text 3/Packages/User/SublimeNodeMCU/SublimeNodeMCU.py", line 48, in sendReceiveScript
    assert len(save_command) < 256, 'Save_command too long: %s bytes' % len(save_command)
AssertionError: Save_command too long: 258 bytes
[Finished in 0.4s with exit code 1]
[shell_cmd: "python" -u "/Users/raf/Library/Application Support/Sublime Text 3/Packages/User/SublimeNodeMCU/SublimeNodeMCU.py" "/Users/raf/Desktop/ESP8266new/ESP8266new.ino"]
[dir: /Users/raf/Desktop/ESP8266new]
[path: /Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/Users/raf/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Lineman.app/Contents/MacOS]

If you think that it's going to take too long time and you don't have it, let me know. I am not going to be mad :), I am actually almost gave up and found VS Code IDE with PlatformIO support and looks like it is not too bad editor. It's just sad that such a nice editor like Sublime is so tricky to set up. Cheers!