probonopd
1/17/2016 - 2:10 PM

Using PlatformIO

Using PlatformIO

sudo apt-get -y install python-pip git
sudo pip install -U platformio
platformio -f init --ide clion --board esp12e
sudo chmod 777 /dev/tty*
platformio serialports list

cp ~/.platformio/packages/framework-arduinoespressif/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino src/

# Set upload speed from 115200 to 921600
echo "upload_speed=921600" >> platformio.ini

# Compile and upload the sketch:
sudo chmod 777 /dev/ttyUSB*
platformio run --target upload

# If you want the latest esp8266/Arduino version from git:
git clone https://github.com/esp8266/Arduino.git ~/.platformio/packages/framework-arduinoespressif/
echo "2.0.0" > .platformio/packages/framework-arduinoespressif/version.txt
rm -rf ~/.platformio/packages/ldscripts/
git clone https://github.com/platformio/platformio-pkg-ldscripts.git --branch esp8266_stage --single-branch ~/.platformio/packages/ldscripts/

# If you want to make it advertise all services on mDNS (NO LONGER NEEDED IN ESP GIT SINCE MERGED TO ESP GIT)
cd .platformio/packages/framework-arduinoespressif/
wget https://patch-diff.githubusercontent.com/raw/esp8266/Arduino/pull/1451.diff
patch -p1 < 1451.diff 
cd -
platformio run --target clean
platformio run --target upload

# Look for suitable devices to upload to
avahi-browse -t -r  "_arduino._tcp"

# Alternatively, just get the IP address of a known hostname
avahi-resolve -h -n esp8266-f1cc73.local

# If there is only one device in the network you can just do:
IP=$(avahi-browse -t -v -r  "_arduino._tcp" 2>/dev/null | grep address | head -n 1 | cut -d "[" -f 2 | cut -d "]" -f 1)
echo $IP
echo "upload_port=$IP" >> platformio.ini

# When I upload now, then it is using OTA!

# Now can import the whole thing into an IDE for editing (supposedly with code completion)
# Install clang (needed for code completion)
# Install Atom and 2 plugins:
# autocomplete-clang
# platformio
# Strangely, syntax highlighting and autocompletion works only for .cpp and not .ino files :-(
# Renaming the ino sketch to cpp does work though it is not clean