Arduino - control LED via wifi based on mysql database value [closed] - mysql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I have:
home server setup with MySQL database and available to network
Arduino with WiFi shield connected to LEDs
Both above are working hunky dory - the Arduino connects to the WiFi and is assigned an IP address.
What I'm now trying to do is write some Arduino code that would read the value stored in the web server database.
If I can work out how to do that, I could take it from there. Could someone provide an example of how to do so?
Extra detail on what I've done so far:
Below code connects to wifi using wifi shield.
Am using Arduino Uno and v 1.05 of IDE
PHP/MYSQL set up on local NAS - ip 192.168.0.102/web/homeserver
So in short, just need to know what's required to query a web server/db from an arduino already connected to the Network.
#include <WiFi.h>
char ssid[] = "SSID_IS_HERE"; // your network SSID (name)
char pass[] = "MY_PASSWORD"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
}
void loop() {
// check the network connection once every 10 seconds:
delay(10000);
printCurrentNet();
}
void printWifiData() {
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
Serial.print(mac[5],HEX);
Serial.print(":");
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Serial.println(mac[0],HEX);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
Serial.print(bssid[5],HEX);
Serial.print(":");
Serial.print(bssid[4],HEX);
Serial.print(":");
Serial.print(bssid[3],HEX);
Serial.print(":");
Serial.print(bssid[2],HEX);
Serial.print(":");
Serial.print(bssid[1],HEX);
Serial.print(":");
Serial.println(bssid[0],HEX);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption,HEX);
Serial.println();
}

first of all depends of your arduino board ,but if you have a shield I assume that you have an arduino uno, for example.
Now you need to write a web service in php for example ,that response the value stored in mysql after a query.
assuming this : Arduino web client
you need to create in you server one file named ledstatus.php so the call is
www.yourwebserver/ledstatus.php?stat=led1
stat is a command to read stat of led
your php file , after mysql query simple response an integer value 0 or 1 with echo ...
now your led is set :
set const int ledPin = 13;
pinMode(ledPin, OUTPUT);
and in this part of code setting web request
client.println("GET /ledstatus.php?stat=led1 HTTP/1.1");
client.println("Host: www.yourwebserver");
client.println("Connection: close");
client.println();
and in this code read a request reponse
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c); // to see the value
digitalWrite(ledPin, atoi(c));
// atoi is a function to convert ascii to integer
}
while(true);
}
Hope this help you

Related

My javax.jms.MessageListener stops receiving messages from IBM MQ Server

I am building a service that continuously consumes messages from a IBM MQ Queue. This service runs in a private cloud with 80 replicas (containers or PODs) listening to the queue. Observing the application logs, I can see about 20 PODs that are not consuming any messages, even though I can check the queue PUT metric counter which shows about 200 req/s (rush hour). Most of the messages stay in the queue for a while (20 seconds) and get expired.
During the non rush hour, the application receives about 40 req/s and can process all the messages without any being expired.
I wonder if there is a limit of active listeners that the IBM MQ Server support? If so, is there any way to increase this limit?
I create a JMSContext using this method:
public JMSContext buildContext() {
if (this.context == null) {
try {
JmsConnectionFactory connection = JmsFactoryFactory.getInstance(JmsConstants.WMQ_PROVIDER).createConnectionFactory();
String hostname = System.getenv("HOSTNAME");
String appName = application.get();
if (hostname != null && !hostname.trim().isEmpty()) {
if (hostname.length() > 28) { // Tamanho máximo da propriedade WMQ_APPLICATIONNAME
appName = hostname.substring(hostname.length() - 28);
} else {
appName = hostname;
}
}
connection.setStringProperty(CommonConstants.WMQ_HOST_NAME, host.get());
connection.setIntProperty(CommonConstants.WMQ_PORT, port.get());
connection.setStringProperty(CommonConstants.WMQ_CHANNEL, channel.get());
connection.setStringProperty(CommonConstants.WMQ_QUEUE_MANAGER, queueManager);
connection.setStringProperty(JmsConstants.USERID, userid);
connection.setStringProperty(JmsConstants.PASSWORD, password);
connection.setBooleanProperty(JmsConstants.USER_AUTHENTICATION_MQCSP, isUserAuthenticationMqcsp);
connection.setIntProperty(CommonConstants.WMQ_CONNECTION_MODE, CommonConstants.WMQ_CM_CLIENT);
connection.setStringProperty(CommonConstants.WMQ_APPLICATIONNAME, appName);
connection.setIntProperty(CommonConstants.WMQ_CLIENT_RECONNECT_OPTIONS, CommonConstants.WMQ_CLIENT_RECONNECT);
LOGGER.info(String.format("buildContext - Parametros da fila a alta [%s],[%s],[%s],[%s],[%s]",
host.get(), channel.get(), application.get(), queueManager, userid));
this.context = connection.createContext();
this.context.start();
this.connectionFactory = connection;
} catch (JMSException e) {
LOGGER.error(String.format("buildContext - error - code: [%s], message: [%s].", e.getErrorCode(), e.getMessage()));
}
}
return this.context;
}
I also configure my message listener using a separate thread as following:
#Override
public void run() {
JMSContext context = factory.buildContext();
this.creditoQueueConsumer = context.createConsumer(context.createQueue(Constantes.PREFIXO_QUEUE.concat(creditoQueue)));
this.creditoQueueConsumer.setMessageListener(mqAltaPlataformaCreditoListener);
// mqAltaPlataformaCreditoListener is an implementation of MessageListener
context.start();
}
The application seems to work fine, however there is a problem when some listeners suddenly stop receiving messages.
I assume the MQ server works as a proxy and then distributes equally messages to all configured listeners, but for some reason, some of the listeners stop receiving messages. The MQ server team mentioned that some connection timeouts are occurring in the server side, as shown in the following picture.
Is there any configuration that can be done in the client to avoid those timeouts ou to avoid the service to stop receiving messages?

Issue with communication between ESP8266 and Arduino UNO

I am having an odd issue. I am providing my codes but I believe the problem is in the wiring which I will explain in a second.
ESP8266 CODE:
#include <SoftwareSerial.h>
SoftwareSerial s(12,14);
#include <ArduinoJson.h>
void setup() {
s.begin(9600);
Serial.begin(9600);
}
void loop() {
StaticJsonBuffer<1000> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["data1"] = 100;
root["data2"] = 200;
Serial.println(s.available());
if(s.available()>0)
{
root.printTo(s);
}
delay(1000);
}
ARDUINO UNO CODE:
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
SoftwareSerial s(5,6);
void setup() {
// Initialize Serial port
Serial.begin(9600);
s.begin(9600);
//while (!Serial) continue;
Serial.println("START");
}
void loop() {
StaticJsonBuffer<1000> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(s);
if (root == JsonObject::invalid()){
Serial.println("JSON invalid");
Serial.println(s.available());
return;
}
Serial.println("JSON received and parsed");
Serial.print("Data 1: ");
int data1=root["data1"];
Serial.println(data1);
Serial.print("Data 2: ");
int data2=root["data2"];
Serial.println(data2);
delay(1000);
}
So the serial monitor of Arduino Uno (after I plug in both arduino and esp8266) says that s.available() = 0. Therefore, it is not recieving JSON. The weird thing is, when i take out the cables from the pins in Arduino, put them in TX and RX pins and then put them back to pins 5 and 6 everything works. When I unplug the arduino and/or ESP and plug them back in the problem repeats- s.availalbe() = 0 (until I do that weird manouver with taking out the cables and putting them back in). I believe there is something I do not understand wiring-wise. I tried connecting them (esp and uno) to the common GND but it still does not work. Does anyone have any ideas what I might be missing here?
Thanks
PS, thats the setup: wiring pic
Okay, I have just managed to fix the problem. I had to change the pins to 0 and 1 like that:
SoftwareSerial s(0,1);
However, this pins are used to communicate with your computer as well, resulting in the arduino ide not being able to upload the code to our arduino while this pins are occupied. Simple solution was to just upload the code and connect NodeMcu ESP8266 afterwards. Hope this helps somone.

Windows Phone - get user selected Cellular system settings

I would need to check if user in phone settings selected option 4G or 3G.
For example if user system settings are 4G but
InternetConnectionProfile.WwanConnectionProfileDetails.GetCurrentDataClass();
Would return different value then 4G I could redirect him to phone settings (ms-settings-cellular://) so that he can disable 4G.
However currently i can't find way to check current user system settings.
I used this in one of my apps:
private const int IANA_INTERFACE_TYPE_WIFI = 71;
private static bool getCurrentConnection()
{
ConnectionProfile internetConnectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
// Check the connection details.
if (internetConnectionProfile.NetworkAdapter.IanaInterfaceType != IANA_INTERFACE_TYPE_WIFI)
{
// Connection is not a Wi-Fi connection.
return false;
//if (internetConnectionProfile.GetConnectionCost().Roaming)
//{
// // User is roaming. Don't send data out.
//}
//if (internetConnectionProfile.GetConnectionCost().ApproachingDataLimit)
//{
// // User is approaching data limit. Send low-resolution images.
//}
//if (internetConnectionProfile.GetConnectionCost().OverDataLimit)
//{
// // User is over data limit. Don't send data out.
//}
}
else
{
//Connection is a Wi-Fi connection. Data restrictions are not necessary.
return true;
}
}
You can also try this: How can I check for 3G, wifi, EDGE, Cellular Networks in Windows Phone 7?

Sending Ready Signal through Socket in flex

I'm developing an AIR project to do machine integration in Flex. In one machine, my app works really good that I'm able to receive data from the machine as I wanted. In the second one, I think it is like we have to send 'READY' kind off signal to the machine for which we will get 'ACK' in return (Handshake) and then only the communication will begin.
How could this 'READY' signal be sent from ActionAcript using Socket.
My ActionScript Class File will look like this..
protected var socket:Socket;
public function init():void
{
socket = new Socket;
socket.addEventListener(Event.CONNECT, onConnect);
socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
socket.addEventListener(Event.CLOSE, onClose);
}
/*** connect to the socket */
public function connect():void
{
if(socket.connected)
{
Status = "Socket is already listening to Port " + socket.remotePort + " in " + socket.remoteAddress;
return;
}
socket.connect("localhost", 5331);
}
/*** handles socket connect event */
private function onConnect(event:Event):void
{
if(socket.connected)
Status = "Connection established successfully from " + Capabilities.os;
else
Status = "Connection failure!";
}
/*** manipulation of received data */
private function onSocketData(event:ProgressEvent):void
{
//Data Recieved
}
/*** handles socket close event */
protected function onClose(event:Event):void
{
Status = "Socket Connection is being closed..";
}
The machine(KR-8900)'s output is RS232.. 8 pin mini din (Male).. and to the system it is db9 pin (as usual).. the serial port communication is done by an External Tool 'SerProxy'. SerProxy will send and receive the data to/from machine-System. Using the app, I will have to connect to the port in the System using Socket and perform Read & Write operations.
My problem here is I don't receive any data in my onSocketData function. Before the communication begins, I need to send READY signal.. I'm stuck here as I don't know how to do this in Flex. Any idea or suggestion are eagerly welcomed.
Socket API allows you to write strings and bytes to a binary socket.
When you socket is connected, you can do something like :
socket.writeUTFBytes("READY");
socket.flush();
You'll have to adapt this code so it will send exactly what you'll need it to send. You can use writeByte to write a null ("\0") character or any control character, too.
To read data, you need to use read methods.

Windows Phone 8 HRESULT: 0X80042706

I'm developing a Windows Phone 8 Application that uses the map control. I have followed the tutorial, but I keep geeting the messagebox error: HRESULT: 0X80042706. Here is the code from the tutorial
protected override void OnNavigatedTo(NavigationEventArgs e)
{
map.ColorMode = MapColorMode.Light; map.CartographicMode = MapCartographicMode.Road; map.LandmarksEnabled = true; map.PedestrianFeaturesEnabled = true; map.ZoomLevel = 17;
routeQuery.TravelMode = TravelMode.Walking; routeQuery.QueryCompleted += rq_QueryCompleted;
base.OnNavigatedTo(e);
}
...
void rq_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e) {
if (null == e.Error) {
//Recommended way to display route on map
Route MyRoute = e.Result;
MapRoute MyMapRoute = new MapRoute(MyRoute);
map.AddRoute(MyMapRoute);
}
else
MessageBox.Show("Error occured:\n" + e.Error.Message);
}
I tried to search what kind of error HRESULT: 0X80042706 was from here, but I have no idea what that meant.
I even tried to switch the if condition to e.Error == null, but still no good. Can anyone help me?
The error is because your device does not support CHAP authentication while connecting to Virtual Disk Service (i.e. Maps)
This is because you don't have an authentication id from Microsoft.
Follow the details here ( for wp8 maps another authentication is required)
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207033(v=vs.105).aspx
I received the same error from the same tutorial, and found it was due to no internet access to my PC (and hence no map data). Restored Internet access and the error resolved itself.
Please once check your Manifestfile and select Capability option click in ID_CAP_MAP.