Ethernet State Machine

Dependencies:   C12832 Client

Committer:
thomasluca
Date:
Thu Oct 29 17:56:30 2020 +0000
Revision:
11:d7b17df4c98a
Parent:
8:e0f3f151c3cc
Child:
13:368c6181b81e
Round-robin Client

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 0:ce7a8546502b 1 #include "mbed.h"
chris 2:9e757151de9b 2 #include "LM75B.h"
chris 5:608f2bf4d3f7 3 #include "C12832.h"
thomasluca 11:d7b17df4c98a 4 #include "EthernetInterface.h"
okano 0:ce7a8546502b 5
chris 6:bb84f3ab523d 6 // Using Arduino pin notation
chris 6:bb84f3ab523d 7 C12832 lcd(D11, D13, D12, D7, D10);
chris 8:e0f3f151c3cc 8 LM75B sensor(D14,D15);
thomasluca 11:d7b17df4c98a 9 AnalogIn pot1 (A0);
okano 0:ce7a8546502b 10
thomasluca 11:d7b17df4c98a 11 int main()
okano 0:ce7a8546502b 12 {
thomasluca 11:d7b17df4c98a 13 printf("Client example\n\r");
thomasluca 11:d7b17df4c98a 14
thomasluca 11:d7b17df4c98a 15 EthernetInterface eth;
thomasluca 11:d7b17df4c98a 16 eth.set_network("192.168.0.20","255.255.255.0","192.168.0.1");
thomasluca 11:d7b17df4c98a 17 eth.connect();
thomasluca 11:d7b17df4c98a 18
thomasluca 11:d7b17df4c98a 19 printf("The client IP address is '%s'\n\r", eth.get_ip_address());
thomasluca 11:d7b17df4c98a 20
thomasluca 11:d7b17df4c98a 21 TCPSocket socket;
thomasluca 11:d7b17df4c98a 22 socket.open(&eth);
thomasluca 11:d7b17df4c98a 23 socket.connect("192.168.0.28",4000);
thomasluca 11:d7b17df4c98a 24
thomasluca 11:d7b17df4c98a 25 uint16_t temperature =(sensor.read());
thomasluca 11:d7b17df4c98a 26 char upperbyte = (temperature >> 8) & 0x00FF;
thomasluca 11:d7b17df4c98a 27 char lowerbyte = temperature & 0x00FF;
thomasluca 11:d7b17df4c98a 28 char pwm = (char)(pot1);
thomasluca 11:d7b17df4c98a 29 char id = 0x14;
thomasluca 11:d7b17df4c98a 30
thomasluca 11:d7b17df4c98a 31 char data[4];
thomasluca 11:d7b17df4c98a 32 data[0] = upperbyte;
thomasluca 11:d7b17df4c98a 33 data[1] = lowerbyte;
thomasluca 11:d7b17df4c98a 34 data[2] = pwm;
thomasluca 11:d7b17df4c98a 35 data[3] = id;
thomasluca 11:d7b17df4c98a 36
thomasluca 11:d7b17df4c98a 37 printf("%d\n", upperbyte);
thomasluca 11:d7b17df4c98a 38 printf("%d\n", lowerbyte);
thomasluca 11:d7b17df4c98a 39
thomasluca 11:d7b17df4c98a 40 // print hex value of temperature on lcd
thomasluca 11:d7b17df4c98a 41 lcd.printf("Temp %.1x\n", sensor.read() );
thomasluca 11:d7b17df4c98a 42 printf(data);
thomasluca 11:d7b17df4c98a 43
thomasluca 11:d7b17df4c98a 44 socket.send(data, 4);
thomasluca 11:d7b17df4c98a 45 socket.close();
okano 0:ce7a8546502b 46 }