One lazy trick the IT guy uses to fix your computer

April 5, 2016

Catchy internet marketing titles aside, this article shows you how to use msra.exe to remotely connect to computers that you control.

Tired of walking through the snow and rain to help with simple helpdesk requests?

Behold the power of Remote Assistance, built right into windows! This feature can be implemented for your environment, assuming that you are using Active Directory and Group Policy with your windows 7/8 environment. This allows you (or your minions) to remotely offer assistance to a user, initiating an “unsolicited” interactive remote desktop connection, with the option for you to request control of their machine. This does not, however, allow you to force remote control of the user’s computer. (There used to be a trick for Windows XP, but it does not work with windows 7/8)

Requirements:

  • The computer is connect to a windows domain that you have control over.
  • You / the helper must have domain credentials with local admin permissions to the remote computer.
  • You must be a domain admin, or have rights to create and manage Group Policy Users and Groups.
  • You may need to configure additional GPO settings for windows firewall and UAC

 

Step 1 – (for you, the helper)

  • Create a shortcut to C:\Windows\System32\msra.exe /offerra

Step 2 – (on your Domain)

  • Create a group that will be allowed to initiate connections.
  • Example “Offer Remote Assistance Helpers”
  • Add users to the group who will have permission to remotely assist others.

Step 3 – create a new GPO in an OU containing computers, called “Remote Assistance Policy”

  • Edit the GPO for Computer Configuration.

Step 3.1

  • Computer Configuration > Policies > Windows Settings > Security Settings > Restricted Groups
  • Right click/ Add Group
  • Type in or Browse for the Active directory group you created above.



Step 3.2

  • Go to Computer Configuration > Administrative Templates > System > Remote Assistance and click Configure Offer Remote Assistance.
  • Enable the policy
    • Permit remote control of this computer using “Allow Helpers to remotely control the computer
    • click Show… next to Helpers
    • Enter the names in domain\user or domain\group format.
    • Enter the group name you created earlier


Or in 2012 R2, is is Configure Offer Remote Assistance


Step 3.3

  • In the same settings folder, enable Solicited Remote Assistance
  • This setting may also be found under

    • Computer Configuration > Administrative Templates > System > Remote Assistance and click Solicited Remote Assistance.



Step 3.4

  • Go to Computer Configuration >Administrative Templates> Windows Components >Remote Desktop Services>Remote Desktop Session Host>Connections
  • Enable “Allow users to connect remotely using Remote Desktop Services”


Step 4

  • Apply this GPO to target computers. This can be done at the root of the domain, or under each OU, depending on desired deployment strategy and security considerations.

Step 5 

  • Perform a Gpupdate on server and clients and test to see if the settings work.

Step 6

  • When a user asks for help, launch the msra from the icon using the shortcut you  created (C:\Windows\System32 msra.exe /offerra)

Testing:

On your PC, launch the new icon


Enter the Computer Name and click next


The user will be prompted with the following:


Once the user clicks Yes, you will see the following.

Notice their desktop image has gone black. This is to preserve network bandwidth for smooth operation. The background will be restored once the support session ends.


You can select the “Request Control” screen


Which prompts the user for permission once again.


 (Tell the user to ignore the checkbox for UAC, unless the user you are helping is a local administrator on their PC. If they do not have local admin rights, they will get a popup asking for credentials, and you will get a black screen with an pause icon. Alternatively, look here)

Once you are done, you or the user may close the Windows Remote Assistance box to end the session!

Happy HelpDesk-ing!


Leave a Comment

Light up musical Christmas Card

December 29, 2015

Three days before Christmas, just as I was falling asleep, I had a vision of a led Christmas tree card. I imagined it would have a number of charliplexed LED’s blinking in a decorative fashion. I had a few ATtiny85 microcontrollers on hand from prior projects, and decided to give it a go.

First off came the experimentation with the Charliplex circuit. I have not played with charlies in a while.  A quick google search revealed some interesting sample code specifically written for the ’85. It has also been a long time since I used my ISP programmer, so I needed a quick reference of the pinout diagrams, for and the 6 pin ISP programming connector and the ISP pins on the ATtiny.

First off was locating some spare parts:

  • 5mm Red and Green LEDs
  • Atmet Tiny85
  • Jumpers
  • Breadboard
  • USBTinyISP programmer
  • Small flat speaker
  • momentary push button

Reference Code used:



The ISP Connections:


Once the ISP Pins were plugged into the micro with jumpers, it was time to program the ATTiny.

Step 1 – Upload Bootloader and select ATtiny85 board, 1 mhz.

Step 2 – Upload simple “Blink” Program

Step 3 – use sample Charliplex code and LEDs


A few quick jumpers on a breadboard yielded some blinkenlights.


First, we try out the sample Charliplex Code

Video – Charliplex code sample

Next, we locate some code that can play back simple tones using a single pin of the ATtiny.

Connecting the speaker is simple


Video: a simple Chromatic scale

 

Next was determining what notes sounded like Christmas Time Is Here from Charlie Brown Christmas.

I played around with a keyboard to find simple tones (not chords) that sound similar to this tune.

To my untuned, musically challenged ear, the beginning sounds somewhat like A, F , F, D, D.

To get the timing right, I added a new “note” called Z which results in an inaudible frequency when played.


I included note Z to add delays between notes.


The final result sounds like this

Video: Christmas Time Is Here

Because code generated using the Arduino IDE is single threaded, you can only play music or flash LEDs using the above code, not both at the same time. Also…this was 2 days before Christmas, I simply did not have enough time to figure out how to do it the right way. I opted for the “hacky” solution, simply alternating between led lights and tunes. Alternativly, I did experiment with two chips, one playing the tunes and one flashing the lights, as seen in the following video.

Video: two AtTiny 85 chips

Next, I assembled the basic card structure ( a Christmas Tree with LEDs) and wired up 4 pairs of LEDs, arranged with the reverse polarity of its sibling.


 

Each row has two LED pairs. These pairs will be charliplexed to 4 pins on the micro.

 

charlieledschristmas


The hookup is roughly as follows for each pair, plus one single LED.


And the messy wiring


I added a simple momentary push button switch to connect the 3v lithium cell to power the circuit. I taped a penny behind it for rigidity.


Finished product – “Christmas Time is Here” with LEDs

 

Mom loved it.

 

Leave a Comment

Instructional: Blink an RGB LED with Arduino

December 1, 2013

When I was at the World’s Maker Faire in NY this past fall, the kind people at Sparkfun gave me several free Arduino’s and WS2811/ws2812 RGB LED breakout kits to give away.

This is a very brief collection of resources needed to get  new users started using a programmable RGB LED. The beauty of these units is their ability to be chained together.

Take a gander at the goods:

Ws2811 / WS2812 RGB Breakout Board


This is actually a prototype board with an Atmel Mega82U

Sparkfun “Arduino Compatable”

 

 

 

 

 

 

 

 

 

 

 

 

And this is what the end product of this tutorial will look like.

Ooooooo the blinky.

WS2811 Breakout board with Arduino


 

 

 

 

 

 

 

 

 

 

 

Setup:

High level overview:  You will be installing the Arduino IDE, copying the neopixel library folder into the arduino libraries folder, then opening the example project file and upload it to the arduino.

You will need the following items:

 

Procedure:

#1
Download and install the latest Arduino environment.


 

 

 

 

 

 

 

 


 

#2
Download the Neo Pixel library.


#3

Install the library by copying it to the correct folder for your Arduino IDE. This varies by operating system. The following instructions are for PC.

Mac holds its files in a different location. Instructions for installing a library on Mac are located here.

Linux users probably won’t be reading this article.

 

For Windows:
Locate your downloaded .zip file and extract it to a folder.



 

#4
Open the folder and change the name of the folder to Adafruit_NeoPixel, removing the  -master, otherwise you will receive an error.


Copy the folder and Paste it into your libraries folder. (My Documents/Arduino/libraries)


#5
Close and re-open the Arduino program



If you receive the following message, you missed step #4


 

 

#6

If all goes as expected, you should be able to open the “strandtest” NeoPixel example code from the File> Examples> menu.


 

You should see the following code: 


 

#7
I would like to call your attention to the comments in the code. They tell you two pieces of information you need to update before uploading your code.
The first is what pin the LED breakout will be connected to.

This is the first line after the include statement:

#define PIN 6

(btw, that is how you use a library, you have to invite it to the party by using the #include.)

We are going to go ahead and hook up the DI pin of the breakout board to digital pin 6. We are going to keep it at pin 6 in the code. If you want to use a different pin number, this is where you would change it.


On the breakout board – DI for Digital In. DO is for digital out.


 

#8
We are going to physically connect the DI (Digital In) to Pin 6 (digital pin 6) on the Arduino.




#9
We will also set up the number of LEDs. In this instance we only have 1 of these breakout boards connected. If we had more than 1, they could be connected in series.

Change this single line of code from a 60 to a 1

Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

#10
Verify that the wiring and environment to ensure we do not perform a smoke test.

Connect the USB cable. 
Tech Tip: If this is your first time connecting the Arduino, your computer may have to load or install a driver to allow your computer to communicate with the Arduino. This driver should be included in the Arduino IDE. If you have problems getting the board to be recognized, you’re gonna have a bad time. See here and here for additional troubleshooting and information. Oh and hereCommunication between the Arduino (Atmel Mega328) and the computer is done over a serial connection. Most Arduinos with a USB connection utilize some form of USB to serial adapter. The board I am using in this particular example uses an FTDI chip to do the USB>serial communication for us. Other boards may use another AVR microcontroller or even implement serial directly in code using v-usb.

 

#11
Click tools > Serial Port and select your COM port.


I tested COM3 – no go.

COM8 is our man


#12
Select the board type from the Tools >Board menu. The Sparkfun Redboard that I am using is Arduino Uno compatible.


#13

Click upload.


If it works you will see some LEDs on the Arduino flashing. On mine it was the red and yellow RX /TX LED’s.



Wonder of Wonders, it works!

Prototyping is fun, but we can do better.

 

 

 

 

 

 

 

 

 

 

Troubleshooting:

If you get errors like this when uploading, go back to step #11. You may have to go back and select a different COM port or a different board.




If your board had a few flashes of lights but no activity on the breakout board, double check the 5v, ground, and DI wire are securely connected and plugged in to the correct pins on the Arduino.

 

Going Further:

-Connect multiple WS2811’s in Series

-Connect multiple WS2811’s in a matrix

Alternative Libraries

OCTOWS2811 by PJRC

Neopixel by Adafruit


 

 

This post was composed and uploaded from Microsoft OneNote 2013
1 Comment

asking big questions

November 21, 2013

I was listening to a podcast recently and the topic of the internet and the accessibility of information was posed, along with a question…

 

Does the vast availability of simple answers (on the internet) condition us to be unable to ask bigger questions?

Are we losing the ability to concentrate on a topic or even read a whole book on a subject without needing all of our questions answered immediately. Are mobile devices an enabler for our shortened attention spans?

 

Data without structure is useless, it needs to be organizzed to become information.

podcast in question.. approx 12 minutes in

http://embedded.fm/episodes/2013/11/20/28-a-lot-of-wish-fulfillment

Leave a Comment

Server Room Environmental Monitoring – Part 2

September 4, 2013

[This post should have been published 2 years ago… oops]

In an earlier post I began working on a Server Room Environmental Monitoring based on an Arduino.

Arduino with Temperature and Light sensors

Arduino with Temperature & Light sensors and potentiometer.

 

This project was started just for fun-  I wanted to learn more about micro controllers (specifically the arduino platform), and partially because I didn’t have room in my technology budget at work to do it the “right way” (not even sure what way that is for a small business…netbotz?). I wanted to improve on my original idea by having it accessible remotely via my network. Thus we end up with our first semi-finished prototype:


prototyping on breadboards

prototyping on breadboards

This device monitors the temperature and ambient light readings and displays the values on an LCD and displays them in a browser windows rendered in html. I have the 2nd iteration pretty much completed, just working through some of the programming issues. [At the time] I wanted to expand the sensors to include multiple i2c temperature sensors, and possibly make the LCD display wireless via Xbee. Later posts will show I ended up using a Nanode with Grove sensors [but I digress as this is documenting the original build.]

Semi- finalized product

Semi- finalized product

Components:

Arduino Duemilanove (ATMEL 328p)
DFRobot Ethernet Shield DFR0110, Powered by a Wiznet W5100
Sparkfun Protoboard (v2)
TEMT6000  Ambient Light Sensor by Vishay via the Sparkfun Breakout Board
JK Device HD44780 Compatable 2 x 16 Char LCD display
Sparkfun SerLCD I2C backpack
Adafruit Arduino enclosure

 

I had to add the Xbee out of necessity (I had them from another project, but when I burned out the FTDI chip on the Arduino I had no way of programming it, but it turned out being rather convenient!)
Two Xbee with a chip based 1mw antenna.
Xbee Explorer Regulated
Xbee Explorer USB

Generic PIR Sensor module from ebay – looks very similar to this.

I have most of the code working. I made the code available as a download. It includes the two libraries for the I2C Serial LCD backpack controls and the LibTemperature library for the I2c temperature module:
Arduino_Environmental_Monitoring_Webserver [this is a .zip file]
The code is also available here in plaintext [here]

 

 

This is how it works:

pull in the libraries for all the different modules
set up the variables to store numbers
some code to control the LCD
Set the pins for the LCD and for the LED
Setup the MAC and IP for the Ethernet Shield
read the sensors and store the values to the variables
convert the C temperature to F and store to a different variable.
Print the values to the display
Send the values inside HTML to the browser
Send the browser a command to refresh every X seconds.

 

The Challenges:

When using my Arduino for another project  I was testing a large number of SMT led’s all at once, pulling a decent amount of current through the 3.3v regulator, far exceeding the 50Ma spec of the L.D.O inside the FTDI. I inadvertently short circuited or over drive the 3.3v line , burning out the FTDI USB to RS232 chip on the board. I ended up utilizing two Xbee modules and connecting one to the TX /RX lines for serial connection. This worked out great, because It forced me to get the Xbee working! I now have 2 Xbee units paired for serial communications.

There were some small issues with the Ethernet Shield. #1. The pin map on this particular model uses (Arduino) pins A4 and A5 to access the SD card, which I am currently using for my I2C temperature sensor communication. There were also issues with the bottom of my proto-shield hitting the ethernet plug and grounding out, so I extended the pins the quick and dirty way by  extending it with pin headers.

The enclosure from Adafruit fit great, but the end plate did not work with the Ethernet shield. I had to discard the plate for the connectors.

 

mounted, splayed

mounted, splayed

Dirty Coding Schemes:

I was getting some odd looking numbers on the LCD screen when testing it in a variety of light and temperature ranges. The number would “print” to the screen, and when it poured over to the 3rd digit, that digit would stay on the screen, regardless of what was being written to the block immediately to the left.

[LCD]

I didn’t bother figuring out how to erase data or clear the screen between refreshes, so in my code I had it over-write 4 blank spaces, then go back to the beginning and write the data value. probably a very dirty way of clearing that part of the screen.

[Browser Refresh]

the arduino code strings together the HTML and streams it to your browser. there is a small snippet of meta html HTTP-EQUIV “REFRESH” that tells your browser to refresh every few seconds to see the new values gathered in the loop code.

[Hard Coded IP Address]

Unfortunately, I found that the DHCP library did not work so well for me. I decided to hard-code my device. this has certain advantages, but makes it less portable. Not everyone uses a class B /16 subnet at home.

 

Final Results:

 

Finalized

Finished device

 

 

guts

internals

 

connectors... the business end

connectors… the business end

 

 

Leave a Comment

IP Cameras

July 11, 2013

So… I finally purchased an Ip Camera, courtesy of the cheapest eBay listing I could find.

It’s a Foscam FI9818W. Pan and Tilt, wired and wireless networking, 2 way audio and Infared illumination. Pretty slick for $45. If only it had relay outputs.


So I plugged it in and got it talking to my network. Here it is looking at the wall.


 I also got it working with the Foscam App for iOS. 2-way audio built in!



Firmware is a bit old… Lets update that.

It also has motion detection and can automatically email photos or upload them to an FTP server.

I set it to email me a few snapshots when it detects motion outside of the regular business day.



Hi

Wave for Mr Blurry Cam!


This post was composed and uploaded from Microsoft OneNote 2013 
Leave a Comment

Nanode Round 3: SketchGarden

March 17, 2012

Speaking of clouds, Sketchgarden.co finally launched in Beta (as of 3-13-2012), allowing the remote upload of Arduino sketches over the internet. As I have already have a working specimen running on my Nanode v5 hardware, I popped in the new atmega328 chip, and it couldn’t have been a simpler process.

This have been a long time coming. In my prior post covering the build of the v5 nanode kit, I included details regarding possible remote firmware uploads and tftp bootloaders. Sketchgarden surpassed my expectations by eliminating the requirement for a server or  any server side configuration. I only need to worry about configuring my code. Minimal hardware is also a big advantage- they were able to fit the code for everything into the Atmel328p chip in flash and eeprom, aside from the external eeprom used to store a permanent  MAC address. (picture)

There are two elements that will be required for widespread adoption – Number one, the release of the bootloader. On twitter, Vic indicated a post-Makerfaire release of the bootloader in a finalized form. In the meantime they plan on shipping pre-loaded chips from wickeddevice.com.

The next element required to get the ball rolling is compatibility with both ENCJ and Wiznet ethernet modules. The Nanode uses the Microchip ENC28J60, while the official Ethernet shield and the Arduino Ethernet use the Wiznet W5100 chip. Both chips are also available as ethernet shields. Support for both chips will enable non-nanode customers to utilize sketchgarden, enabling WickedDevice to reach a critical mass. Boom.

The WickedDevice Nanode V5 is available assembled($49)or as a kit ($39, includes FTDI adapter). The Sketchgarden chip comes preloaded with the custom Sketchgarden bootloader, but is currently listed as unavailable,-It may not be offered for sale until the initial beta is complete.

A big thanks to Vic and Dirk at Wicked Device. You can find out more information at WickedDevice.com, or check out Vic and Dirk on Twitter. You can also check out their blog.

 

ON TO THE GOODS 

I went ahead and documented the process, including specifics for OSx users:

In a nutshell: Install new Chip, configure network settings locally, set up new nanode on sketchgarden.co, Compile hex file and convert to a binary image. Then upload image and assign to your device. Boom. Done.

 

#1. Install New Chip (available soon at wickeddevice)

chip swap

You should use caution when removing microchips… 

#2 Connect to your device on your local network, and change the settings to fit your network as necessary. The settings will be stored to the atmel328 eeprom and will remain static until changed.

Note: The sketch  seen below is called “SketchGarden Config” to re-load on your device should you need to re-configure your IP address, should you decide not to incorporate 

This is the pre-loaded Sketchgarden Config Sketch. It will be replaced with your sketch on first upload. Don’t forget the copy down your API key from this screen.

#3 Connect your twitter account at  sketchgarden.co

You don’t have to tweet, but you gotta have a twitter.

#4 Add your device with the Api key you obtained before.

 

 

#5 Compiling your working Nanode/Arduino sketch to hex:
Go to your working arduino / Nanode sketch. Hold down the Shift key and click the > compile button. Look at the last section and identify the file path. If you are cool like me, and have OSX, your files will be hidden in some folder that you can’t see.

/var/folders/ blablabla

That’s ok, here is a shortcut for OSX users. From finder, select Go, then Go To Folder, then paste in your long folder location.

complicated eh?

For me it was /var/folders/RZ/RZv65MxvH4GoCj14HxLTjk+++TI/-Tmp-/build654337670699641674.tmp/  sketchname.cpp.hex

 

locate your file and copy it somewhere you can see it.

organized files? I think not.

Now convert  the hex file to a bin file using the tool from sketchgarden – currently a java program called HexToImage.jar, (located in the help menu from sketchgarden.co).
Open a terminal window, and navigate to the directory with your .hex file and the hextoimage.jar app.
Type in java -jar HexToImage.jar yourfilehere.cpp.hex yourfilehere.bin

For me, it was:

cd desktop
cd environmental
java -jar HexToImage.jar PachubeV3_LibTemp_Motion_light_Webserver_SEEDLCD_JH.cpp.hex PachubeV3_SeedLCD_for_Sketchgarden.bin

 

I’m going to bash your head in.

#6 Upload To Sketchgarden

Take your compiled and converted .bin file and upload it as a new sketch. Dont forget to copy in your source code to remind you of what this file does.

 

It’s Peanut Butter sketchy time

#7 Upload to your nanode

click and  drag the file from the left over to the grey square… it took me a few tries, the page seems buggy. then click Upload Sketch.

Master preview artist, at your service.

I dont do GIFS.

# 8 Wait a few minutes, then give up thinking it failed….hours later return and rejoice that it actually did work, but you were to impatient the first time around!

patience

Win.

 

Somewhere along the line I had an issue with my nanode resetting every time I try to capture from more than 3 sensors. Currently, I am only capturing Temperature and Light information. The motion capture device (A PIR motion sensor) was randomly freezing my Nanode and causing it to stop reporting data. Unfortunately I uploaded my old code in this ketch, but I should be able to recall what I did to get it to work. I beleive i excluded the reading of those sensor pins, and filled the values with an arbitrary or duplicate value.

 

It doesn’t look like much, but I made it.

 

final enclosure

final enclosure. 

 

Leave a Comment

Nanode: Round 2 – Pachube with Various sensors

January 5, 2012

Webservers are so 1990’s. We need fresh ways of collecting and displaying data. Too bad there isn’t a “cloud” service out there for that.

Oh, wait, There is!

Following the basic code on the Nanode website I was able to set up my own Pachube (Now COSM Xively) account and configure my nanode to stream data over to their logging service.

Here is the list of items used in this build:

Nanode V5 by WickedDevice
ModernDevice TempSensor (i2c temperature sensor) from Liquidware, which is a breakout for the TMP421  from Texas Instruments.
Serial LCD v1.1 – 16×2 “Twig” Grove display from SeeedStudios SeeedStudio “Grove” light sensor v 1.0
PIR sensor (Motion Detector) , Ebay

Programming:

Sample Code

The internal IP address is staticly defined, along with the DNS settings for pachube.com. This was cobbled together in november / december, and since then new code is available for proper DNS resoloution.

Upon power up, the Nanode checks it is connected to the network, then polls the sensors and stores them to variables. It refreshes the LCD and “prints” it to the screen, prints to the serial port, and shoots the data up to pachube.com

 

As seen in my office, hanging precariously off my booklamp.

 

 

 

Leave a Comment

CODE:SEEDLCD_JH

December 20, 2011

Download [zip] PachubeV3_LibTemp_Motion_light_Webserver_SEEDLCD_JH

————————

 

/*
* Arduino + Analog Sensors Posted to Pachube
*      Original Source Created on: Aug 31, 2011
*          Author: Victor Aprea
*   Documentation: http://wickeddevice.com
*
*       Source Revision: 587
*
* Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0
*    Utilized in the following example by JarenHavell.com in “Nanode Round 2”
*
* HAREDWARE SETUP
* Modern Device TempSensor i2c Temperature sensor – analog pins 2,3,4,5 – from liquidware http://www.liquidware.com/shop/show/SEN-TMP/Temp+Sensor
* Generic Motion Sensor Analog pin 0 – from Ebay
* Grove – Serial LCD – “twig serial LCD” 2×16 chars-  from Seeedstudios  http://www.seeedstudio.com/wiki/index.php?title=Twig_-_Serial_LCD
*
*
*
*
*/

#include “EtherShield.h”
//for temperature Sensor
#include “Wire.h”
#include “LibTemperature.h”
#include <SerialLCD.h>
#include <NewSoftSerial.h> //this is a must
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* The following #defines govern the behavior of the sketch. You can console outputs using the Serial Monitor
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#define MY_MAC_ADDRESS {0x54,0x55,0x58,0x10,0x00,0x25}               // must be uniquely defined for all Nanodes, e.g. just change the last number
//#define USE_DHCP                                                     // comment out this line to use static network parameters
#define PACHUBE_API_KEY “INSERT YOUR OWN PACHUBE KEY BETWEEN THE QUOTES” // change this to your API key
#define HTTPFEEDPATH “/v2/feeds/#####”                               // change this to the relative URL of your feed, #’s replaced with your own feed.
#define SENSOR2_ANALOG_PIN 1
#define SENSOR3_ANALOG_PIN 0
//************************************************
//-the temperature stuff – variables
LibTemperature temp = LibTemperature(0); // more temperature variable stuff
//*************************************************

SerialLCD slcd(5,6); //assign soft serial pins 5 as RX, 6 as TX.
//Connect 6 to the RX of LCD, and 5 to TX of LCD.

//sets size of LCD
const int numRows = 2;
const int numCols = 16;

#define DELAY_BETWEEN_PACHUBE_POSTS_MS 15000L
#define SERIAL_BAUD_RATE 19200

#ifndef USE_DHCP // then you need to supply static network parameters, only if you are not using DHCP
#define MY_IP_ADDRESS { 192,168,  1,175}
#define MY_NET_MASK   {255,255, 255,  0}
#define MY_GATEWAY    { 192,168,  1,  1}
#define MY_DNS_SERVER {  8,  8,  8,  8}
#endif

// change the template to be consistent with your datastreams: see http://api.pachube.com/v2/
#define FEED_POST_MAX_LENGTH 256
static char feedTemplate[] = “{\”version\”:\”1.0.0\”,\”datastreams\”:[{\”id\”:\”sensor1\”, \”current_value\”:\”%d\”},{\”id\”:\”sensor2\”,\”current_value\”:\”%d\”},{\”id\”:\”sensor3\”,\”current_value\”:\”%d\”}]}”;
static char feedPost[FEED_POST_MAX_LENGTH] = {0}; // this will hold your filled out template
uint8_t fillOutTemplateWithSensorValues(uint16_t node_id, uint16_t sensorValue1, uint16_t sensorValue2, uint16_t sensorValue3){
// change this function to be consistent with your feed template, it will be passed the node id and four sensor values by the sketch
// if you return (1) this the sketch will post the contents of feedPost to Pachube, if you return (0) it will not post to Pachube
// you may use as much of the passed information as you need to fill out the template

snprintf(feedPost, FEED_POST_MAX_LENGTH, feedTemplate, sensorValue1, sensorValue2,sensorValue3); // this simply populates the current_value filed with sensorValue1
return (1);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* You shouldn’t need to make changes below here for configuring the sketch
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

// mac and ip (if not using DHCP) have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = MY_MAC_ADDRESS;

// IP address of the host being queried to contact (IP of the first portion of the URL):
static uint8_t websrvip[4] = {173,203, 98, 29 }; // should be resolved through DNS

#ifndef USE_DHCP
// use the provided static parameters
static uint8_t myip[4]      = MY_IP_ADDRESS;
static uint8_t mynetmask[4] = MY_NET_MASK;
static uint8_t gwip[4]      = MY_GATEWAY;
static uint8_t dnsip[4]     = MY_DNS_SERVER;
#else
// these will all be resolved through DHCP
static uint8_t dhcpsvrip[4] = { 0,0,0,0 };
static uint8_t myip[4]      = { 0,0,0,0 };
static uint8_t mynetmask[4] = { 0,0,0,0 };
static uint8_t gwip[4]      = { 0,0,0,0 };
static uint8_t dnsip[4]     = { 0,0,0,0 };
#endif

long lastPostTimestamp;
boolean firstTimeFlag = true;
// global string buffer for hostname message:
#define FEEDHOSTNAME “api.pachube.com\r\nX-PachubeApiKey: ” PACHUBE_API_KEY
#define FEEDWEBSERVER_VHOST “api.pachube.com”

static char hoststr[150] = FEEDWEBSERVER_VHOST;

#define BUFFER_SIZE 550
static uint8_t buf[BUFFER_SIZE+1];

EtherShield es=EtherShield();

void setup(){
Serial.begin(SERIAL_BAUD_RATE);
Serial.println(“Nanode + LibTemp Sensor + Pachube = Awesome”);
// Initialise SPI interface
es.ES_enc28j60SpiInit();

// initialize ENC28J60
es.ES_enc28j60Init(mymac, 8);

#ifdef USE_DHCP
acquireIPAddress();
#endif

printNetworkParameters();

//init the ethernet/ip layer:
es.ES_init_ip_arp_udp_tcp(mymac,myip, 80);

// init the web client:
es.ES_client_set_gwip(gwip);  // e.g internal IP of dsl router
es.ES_dnslkup_set_dnsip(dnsip); // generally same IP as router

Serial.println(“Awaiting Client Gateway”);
while(es.ES_client_waiting_gw()){
int plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
es.ES_packetloop_icmp_tcp(buf,plen);
}
Serial.println(“Client Gateway Complete, Resolving Host”);

resolveHost(hoststr, websrvip);
Serial.print(“Resolved host: “);
Serial.print(hoststr);
Serial.print(” to IP: “);
printIP(websrvip);
Serial.println();

 

es.ES_client_set_wwwip(websrvip);

lastPostTimestamp = millis();
}

void loop(){
long currentTime = millis();

int plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
es.ES_packetloop_icmp_tcp(buf,plen);

if(currentTime – lastPostTimestamp > DELAY_BETWEEN_PACHUBE_POSTS_MS || firstTimeFlag){
firstTimeFlag = false;
uint16_t sensorValue1 = ((temp.GetTemperature() * 9 / 5) + 32);;
uint16_t sensorValue2 = analogRead(SENSOR2_ANALOG_PIN);
uint16_t sensorValue3 = analogRead(SENSOR3_ANALOG_PIN);

if(fillOutTemplateWithSensorValues(0, sensorValue1, sensorValue2, sensorValue3)){
Serial.print(“Posting sensor values to Pachube: “);
Serial.print(sensorValue1, DEC);
Serial.print(“, “);
Serial.print(sensorValue2, DEC);
Serial.print(“, “);
Serial.print(sensorValue3, DEC);
Serial.print(“, “);
Serial.println();

//begin coimmunication, turn on display, turn on backlight
slcd.begin();
slcd.clear();
slcd.backlight();

//Col, row
slcd.setCursor(0,0);  // Scroll to X,Y position
slcd.print(“Temp”);
slcd.setCursor(0,1);  // Scroll to X,Y position
slcd.print(sensorValue1, DEC);
slcd.print(“F”);

slcd.setCursor(5,0);  // Scroll to X,Y position
slcd.print(“Motion”);
slcd.setCursor(5,1);  // Scroll to X,Y position
slcd.print(sensorValue2, DEC);

slcd.setCursor(12,0);  // Scroll to X,Y position
slcd.print(“Lht”);
slcd.setCursor(12,1);  // Scroll to X,Y position
slcd.print(sensorValue3, DEC);

es.ES_client_http_post(PSTR(HTTPFEEDPATH),PSTR(FEEDWEBSERVER_VHOST),PSTR(FEEDHOSTNAME), PSTR(“PUT “), feedPost, &sensor_feed_post_callback);
}
lastPostTimestamp = currentTime;

 

}

}

#ifdef USE_DHCP
void acquireIPAddress(){
uint16_t dat_p;
long lastDhcpRequest = millis();
uint8_t dhcpState = 0;
Serial.println(“Sending initial DHCP Discover”);
es.ES_dhcp_start( buf, mymac, myip, mynetmask,gwip, dnsip, dhcpsvrip );

while(1) {
// handle ping and wait for a tcp packet
int plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

dat_p=es.ES_packetloop_icmp_tcp(buf,plen);
//    dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
if(dat_p==0) {
int retstat = es.ES_check_for_dhcp_answer( buf, plen);
dhcpState = es.ES_dhcp_state();
// we are idle here
if( dhcpState != DHCP_STATE_OK ) {
if (millis() > (lastDhcpRequest + 10000L) ){
lastDhcpRequest = millis();
// send dhcp
Serial.println(“Sending DHCP Discover”);
es.ES_dhcp_start( buf, mymac, myip, mynetmask,gwip, dnsip, dhcpsvrip );
}
}
else {
return;
}
}
}
}
#endif

// hostName is an input parameter, ipAddress is an outputParame
void resolveHost(char *hostName, uint8_t *ipAddress){
es.ES_dnslkup_request(buf, (uint8_t*)hostName );
while(1){
int plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
es.ES_packetloop_icmp_tcp(buf,plen);
if(es.ES_udp_client_check_for_dns_answer(buf, plen)) {
uint8_t *websrvipptr = es.ES_dnslkup_getip();
for(int on=0; on <4; on++ ) {
ipAddress[on] = *websrvipptr++;
}
return;
}
}
}

void sensor_feed_post_callback(uint8_t statuscode,uint16_t datapos){
Serial.println();
Serial.print(“Status Code: “);
Serial.println(statuscode, HEX);
Serial.print(“Datapos: “);
Serial.println(datapos, DEC);
Serial.println(“PAYLOAD”);
for(int i = 0; i < 100; i++){
Serial.print(byte(buf[i]));
}

Serial.println();
Serial.println();
}

// Output a ip address from buffer from startByte
void printIP( uint8_t *buf ) {
for( int i = 0; i < 4; i++ ) {
Serial.print( buf[i], DEC );
if( i<3 )
Serial.print( “.” );
}
}

void printNetworkParameters(){
Serial.print( “My IP: ” );
printIP( myip );
Serial.println();

Serial.print( “Netmask: ” );
printIP( mynetmask );
Serial.println();

Serial.print( “DNS IP: ” );
printIP( dnsip );
Serial.println();

Serial.print( “GW IP: ” );
printIP( gwip );
Serial.println();
}

 

 

1 Comment

Nanode: Round 1 – Webserver and temperature sensor

September 26, 2011

First project with the nanode was getting a sensor to display the current temperature, then display it on a self refreshing webpage. Pretty simple, since I have already done this before. Just a few minor differences in how the libraries work. Currently it is pulling the temperature data from a ModernDevice temp sensor, and displaying on this website, which refreshes every second. See it in action here.

My Code:

Nanode_Server [.ZIP FILE!]
Contains: (my simple Arduino Sketch, Libraries for the Nanode compatable ethernet shield and the Lib Temp Sensor )

Code examples:
https://github.com/Nanode/Webserver-Live-Thermistor-Reading/blob/master/Webserver_Live_Thermistor_Reading.pde
http://www.liquidware.com/apps/show/77

Programming help:
http://arduino.cc/en/Reference/Array
http://dereenigne.org/electronics/arduino/arduino-float-to-string

hardware:
http://shop.moderndevice.com/products/tmp421-temperature-sensor   (As seen in my prior post)
http://www.jarenhavell.com/blog/nanodefirstimpressions/

Leave a Comment

Next Page »